summaryrefslogtreecommitdiff
path: root/doc/progs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/progs')
-rw-r--r--doc/progs/cat.go22
-rw-r--r--doc/progs/cat_rot13.go14
-rw-r--r--doc/progs/fd.go62
-rw-r--r--doc/progs/file.go62
-rw-r--r--doc/progs/helloworld3.go6
-rwxr-xr-xdoc/progs/run2
6 files changed, 84 insertions, 84 deletions
diff --git a/doc/progs/cat.go b/doc/progs/cat.go
index 5925c8da2..b46487fd2 100644
--- a/doc/progs/cat.go
+++ b/doc/progs/cat.go
@@ -5,23 +5,23 @@
package main
import (
- "fd";
+ "file";
"flag";
)
-func cat(file *fd.FD) {
+func cat(f *file.File) {
const NBUF = 512;
var buf [NBUF]byte;
for {
- switch nr, er := file.Read(buf); true {
+ switch nr, er := f.Read(buf); true {
case nr < 0:
- print("error reading from ", file.String(), ": ", er.String(), "\n");
+ print("error reading from ", f.String(), ": ", er.String(), "\n");
sys.Exit(1);
case nr == 0: // EOF
return;
case nr > 0:
- if nw, ew := fd.Stdout.Write(buf[0:nr]); nw != nr {
- print("error writing from ", file.String(), ": ", ew.String(), "\n");
+ if nw, ew := file.Stdout.Write(buf[0:nr]); nw != nr {
+ print("error writing from ", f.String(), ": ", ew.String(), "\n");
}
}
}
@@ -30,15 +30,15 @@ func cat(file *fd.FD) {
func main() {
flag.Parse(); // Scans the arg list and sets up flags
if flag.NArg() == 0 {
- cat(fd.Stdin);
+ cat(file.Stdin);
}
for i := 0; i < flag.NArg(); i++ {
- file, err := fd.Open(flag.Arg(i), 0, 0);
- if file == nil {
+ f, err := file.Open(flag.Arg(i), 0, 0);
+ if f == nil {
print("can't open ", flag.Arg(i), ": error ", err, "\n");
sys.Exit(1);
}
- cat(file);
- file.Close();
+ cat(f);
+ f.Close();
}
}
diff --git a/doc/progs/cat_rot13.go b/doc/progs/cat_rot13.go
index d2b017bd2..27d1e467f 100644
--- a/doc/progs/cat_rot13.go
+++ b/doc/progs/cat_rot13.go
@@ -5,7 +5,7 @@
package main
import (
- "fd";
+ "file";
"flag";
"os";
)
@@ -63,7 +63,7 @@ func cat(r reader) {
case nr == 0: // EOF
return;
case nr > 0:
- nw, ew := fd.Stdout.Write(buf[0:nr]);
+ nw, ew := file.Stdout.Write(buf[0:nr]);
if nw != nr {
print("error writing from ", r.String(), ": ", ew.String(), "\n");
}
@@ -74,15 +74,15 @@ func cat(r reader) {
func main() {
flag.Parse(); // Scans the arg list and sets up flags
if flag.NArg() == 0 {
- cat(fd.Stdin);
+ cat(file.Stdin);
}
for i := 0; i < flag.NArg(); i++ {
- file, err := fd.Open(flag.Arg(i), 0, 0);
- if file == nil {
+ f, err := file.Open(flag.Arg(i), 0, 0);
+ if f == nil {
print("can't open ", flag.Arg(i), ": error ", err, "\n");
sys.Exit(1);
}
- cat(file);
- file.Close();
+ cat(f);
+ f.Close();
}
}
diff --git a/doc/progs/fd.go b/doc/progs/fd.go
deleted file mode 100644
index c99c87777..000000000
--- a/doc/progs/fd.go
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package fd
-
-import (
- "os";
- "syscall";
-)
-
-type FD struct {
- fildes int64; // file descriptor number
- name string; // file name at Open time
-}
-
-func newFD(fd int64, name string) *FD {
- if fd < 0 {
- return nil
- }
- return &FD{fd, name}
-}
-
-var (
- Stdin = newFD(0, "/dev/stdin");
- Stdout = newFD(1, "/dev/stdout");
- Stderr = newFD(2, "/dev/stderr");
-)
-
-func Open(name string, mode int64, perm int64) (fd *FD, err *os.Error) {
- r, e := syscall.Open(name, mode, perm);
- return newFD(r, name), os.ErrnoToError(e)
-}
-
-func (fd *FD) Close() *os.Error {
- if fd == nil {
- return os.EINVAL
- }
- r, e := syscall.Close(fd.fildes);
- fd.fildes = -1; // so it can't be closed again
- return nil
-}
-
-func (fd *FD) Read(b []byte) (ret int, err *os.Error) {
- if fd == nil {
- return -1, os.EINVAL
- }
- r, e := syscall.Read(fd.fildes, &b[0], int64(len(b)));
- return int(r), os.ErrnoToError(e)
-}
-
-func (fd *FD) Write(b []byte) (ret int, err *os.Error) {
- if fd == nil {
- return -1, os.EINVAL
- }
- r, e := syscall.Write(fd.fildes, &b[0], int64(len(b)));
- return int(r), os.ErrnoToError(e)
-}
-
-func (fd *FD) String() string {
- return fd.name
-}
diff --git a/doc/progs/file.go b/doc/progs/file.go
new file mode 100644
index 000000000..e2ecf9209
--- /dev/null
+++ b/doc/progs/file.go
@@ -0,0 +1,62 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package file
+
+import (
+ "os";
+ "syscall";
+)
+
+type File struct {
+ fd int64; // file descriptor number
+ name string; // file name at Open time
+}
+
+func newFile(fd int64, name string) *File {
+ if fd < 0 {
+ return nil
+ }
+ return &File{fd, name}
+}
+
+var (
+ Stdin = newFile(0, "/dev/stdin");
+ Stdout = newFile(1, "/dev/stdout");
+ Stderr = newFile(2, "/dev/stderr");
+)
+
+func Open(name string, mode int64, perm int64) (file *File, err *os.Error) {
+ r, e := syscall.Open(name, mode, perm);
+ return newFile(r, name), os.ErrnoToError(e)
+}
+
+func (file *File) Close() *os.Error {
+ if file == nil {
+ return os.EINVAL
+ }
+ r, e := syscall.Close(file.fd);
+ file.fd = -1; // so it can't be closed again
+ return nil
+}
+
+func (file *File) Read(b []byte) (ret int, err *os.Error) {
+ if file == nil {
+ return -1, os.EINVAL
+ }
+ r, e := syscall.Read(file.fd, &b[0], int64(len(b)));
+ return int(r), os.ErrnoToError(e)
+}
+
+func (file *File) Write(b []byte) (ret int, err *os.Error) {
+ if file == nil {
+ return -1, os.EINVAL
+ }
+ r, e := syscall.Write(file.fd, &b[0], int64(len(b)));
+ return int(r), os.ErrnoToError(e)
+}
+
+func (file *File) String() string {
+ return file.name
+}
diff --git a/doc/progs/helloworld3.go b/doc/progs/helloworld3.go
index 59aebc721..18fa594f0 100644
--- a/doc/progs/helloworld3.go
+++ b/doc/progs/helloworld3.go
@@ -4,12 +4,12 @@
package main
-import fd "fd"
+import file "file"
func main() {
hello := []byte{'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '\n'};
- fd.Stdout.Write(hello);
- file, err := fd.Open("/does/not/exist", 0, 0);
+ file.Stdout.Write(hello);
+ file, err := file.Open("/does/not/exist", 0, 0);
if file == nil {
print("can't open file; err=", err.String(), "\n");
sys.Exit(1);
diff --git a/doc/progs/run b/doc/progs/run
index f93bb65a6..6f047b155 100755
--- a/doc/progs/run
+++ b/doc/progs/run
@@ -6,7 +6,7 @@
rm -f *.6
for i in \
- fd.go \
+ file.go \
helloworld.go \
helloworld2.go \
helloworld3.go \