summaryrefslogtreecommitdiff
path: root/src/pkg/os/file_plan9.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-07-08 09:16:22 +0200
committerOndřej Surý <ondrej@sury.org>2011-07-08 09:16:22 +0200
commitab23f6dab91e6ec615481c4b3e77e4639c3f871b (patch)
treef897fd3be56fdc3599a88df375c76bc172108fd1 /src/pkg/os/file_plan9.go
parent8d00b02d82d86abe51773dc2c1751843bb538ae5 (diff)
downloadgolang-ab23f6dab91e6ec615481c4b3e77e4639c3f871b.tar.gz
Imported Upstream version 2011.07.07upstream-weekly/2011.07.07
Diffstat (limited to 'src/pkg/os/file_plan9.go')
-rw-r--r--src/pkg/os/file_plan9.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pkg/os/file_plan9.go b/src/pkg/os/file_plan9.go
index b0c42d14d..03792191e 100644
--- a/src/pkg/os/file_plan9.go
+++ b/src/pkg/os/file_plan9.go
@@ -9,6 +9,32 @@ import (
"syscall"
)
+// File represents an open file descriptor.
+type File struct {
+ fd int
+ name string
+ dirinfo *dirInfo // nil unless directory being read
+ nepipe int // number of consecutive EPIPE in Write
+}
+
+// Fd returns the integer Unix file descriptor referencing the open file.
+func (file *File) Fd() int {
+ if file == nil {
+ return -1
+ }
+ return file.fd
+}
+
+// NewFile returns a new File with the given file descriptor and name.
+func NewFile(fd int, name string) *File {
+ if fd < 0 {
+ return nil
+ }
+ f := &File{fd: fd, name: name}
+ runtime.SetFinalizer(f, (*File).Close)
+ return f
+}
+
// Auxiliary information if the File describes a directory
type dirInfo struct {
buf [syscall.STATMAX]byte // buffer for directory I/O