OSDN Git Service

Update Go library to r60.
[pf3gnuchains/gcc-fork.git] / libgo / go / os / file.go
index 3aad802..4335d45 100644 (file)
@@ -2,39 +2,19 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// The os package provides a platform-independent interface to operating
-// system functionality.  The design is Unix-like.
+// Package os provides a platform-independent interface to operating system
+// functionality.  The design is Unix-like.
+// The os interface is intended to be uniform across all operating systems.
+// Features not generally available appear in the system-specific package syscall.
 package os
 
 import (
-       "runtime"
        "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 { return file.fd }
-
 // Name returns the name of the file as presented to Open.
 func (file *File) Name() string { return file.name }
 
-// 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, name, nil, 0}
-       runtime.SetFinalizer(f, (*File).Close)
-       return f
-}
-
 // Stdin, Stdout, and Stderr are open Files pointing to the standard input,
 // standard output, and standard error file descriptors.
 var (
@@ -85,7 +65,7 @@ func (file *File) Read(b []byte) (n int, err Error) {
        if file == nil {
                return 0, EINVAL
        }
-       n, e := syscall.Read(file.fd, b)
+       n, e := file.read(b)
        if n < 0 {
                n = 0
        }
@@ -107,7 +87,7 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
                return 0, EINVAL
        }
        for len(b) > 0 {
-               m, e := syscall.Pread(file.fd, b, off)
+               m, e := file.pread(b, off)
                if m == 0 && !iserror(e) {
                        return n, EOF
                }
@@ -129,7 +109,7 @@ func (file *File) Write(b []byte) (n int, err Error) {
        if file == nil {
                return 0, EINVAL
        }
-       n, e := syscall.Write(file.fd, b)
+       n, e := file.write(b)
        if n < 0 {
                n = 0
        }
@@ -150,7 +130,7 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
                return 0, EINVAL
        }
        for len(b) > 0 {
-               m, e := syscall.Pwrite(file.fd, b, off)
+               m, e := file.pwrite(b, off)
                if iserror(e) {
                        err = &PathError{"write", file.name, Errno(e)}
                        break
@@ -167,7 +147,7 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
 // relative to the current offset, and 2 means relative to the end.
 // It returns the new offset and an Error, if any.
 func (file *File) Seek(offset int64, whence int) (ret int64, err Error) {
-       r, e := syscall.Seek(file.fd, offset, whence)
+       r, e := file.seek(offset, whence)
        if !iserror(e) && file.dirinfo != nil && r != 0 {
                e = syscall.EISDIR
        }
@@ -183,9 +163,7 @@ func (file *File) WriteString(s string) (ret int, err Error) {
        if file == nil {
                return 0, EINVAL
        }
-       b := syscall.StringByteSlice(s)
-       b = b[0 : len(b)-1]
-       return file.Write(b)
+       return file.Write([]byte(s))
 }
 
 // Mkdir creates a new directory with the specified name and permission bits.