diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
commit | 505c19580e0f43fe5224431459cacb7c21edd93d (patch) | |
tree | 79e2634c253d60afc0cc0b2f510dc7dcbb48497b /doc/progs/file.go | |
parent | 1336a7c91e596c423a49d1194ea42d98bca0d958 (diff) | |
download | golang-505c19580e0f43fe5224431459cacb7c21edd93d.tar.gz |
Imported Upstream version 1upstream/1
Diffstat (limited to 'doc/progs/file.go')
-rw-r--r-- | doc/progs/file.go | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/doc/progs/file.go b/doc/progs/file.go deleted file mode 100644 index 2875ce73a..000000000 --- a/doc/progs/file.go +++ /dev/null @@ -1,89 +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 file - -import ( - "os" - "syscall" -) - -type File struct { - fd int // file descriptor number - name string // file name at Open time -} - -func newFile(fd int, name string) *File { - if fd < 0 { - return nil - } - return &File{fd, name} -} - -var ( - Stdin = newFile(syscall.Stdin, "/dev/stdin") - Stdout = newFile(syscall.Stdout, "/dev/stdout") - Stderr = newFile(syscall.Stderr, "/dev/stderr") -) - -func OpenFile(name string, mode int, perm uint32) (file *File, err os.Error) { - r, e := syscall.Open(name, mode, perm) - if e != 0 { - err = os.Errno(e) - } - return newFile(r, name), err -} - -const ( - O_RDONLY = syscall.O_RDONLY - O_RDWR = syscall.O_RDWR - O_CREATE = syscall.O_CREAT - O_TRUNC = syscall.O_TRUNC -) - -func Open(name string) (file *File, err os.Error) { - return OpenFile(name, O_RDONLY, 0) -} - -func Create(name string) (file *File, err os.Error) { - return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) -} - -func (file *File) Close() os.Error { - if file == nil { - return os.EINVAL - } - e := syscall.Close(file.fd) - file.fd = -1 // so it can't be closed again - if e != 0 { - return os.Errno(e) - } - 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) - if e != 0 { - err = os.Errno(e) - } - return int(r), err -} - -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) - if e != 0 { - err = os.Errno(e) - } - return int(r), err -} - -func (file *File) String() string { - return file.name -} |