From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libgo/go/os/file_unix.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 libgo/go/os/file_unix.go (limited to 'libgo/go/os/file_unix.go') diff --git a/libgo/go/os/file_unix.go b/libgo/go/os/file_unix.go new file mode 100644 index 000000000..57d4a477f --- /dev/null +++ b/libgo/go/os/file_unix.go @@ -0,0 +1,110 @@ +// 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 os + +import ( + "runtime" + "syscall" +) + +// Auxiliary information if the File describes a directory +type dirInfo struct { + buf []byte // buffer for directory I/O + dir *syscall.DIR // from opendir +} + +// DevNull is the name of the operating system's ``null device.'' +// On Unix-like systems, it is "/dev/null"; on Windows, "NUL". +const DevNull = "/dev/null" + +// Open opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) +// if applicable. If successful, methods on the returned File can be used for I/O. +// It returns the File and an Error, if any. +func Open(name string, flag int, perm uint32) (file *File, err Error) { + r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, perm) + if e != 0 { + return nil, &PathError{"open", name, Errno(e)} + } + + // There's a race here with fork/exec, which we are + // content to live with. See ../syscall/exec.go + if syscall.O_CLOEXEC == 0 { // O_CLOEXEC not supported + syscall.CloseOnExec(r) + } + + return NewFile(r, name), nil +} + +// Close closes the File, rendering it unusable for I/O. +// It returns an Error, if any. +func (file *File) Close() Error { + if file == nil || file.fd < 0 { + return EINVAL + } + var err Error + if e := syscall.Close(file.fd); e != 0 { + err = &PathError{"close", file.name, Errno(e)} + } + + if file.dirinfo != nil { + if libc_closedir(file.dirinfo.dir) < 0 && err == nil { + err = &PathError{"closedir", file.name, Errno(syscall.GetErrno())} + } + } + + file.fd = -1 // so it can't be closed again + + // no need for a finalizer anymore + runtime.SetFinalizer(file, nil) + return err +} + +// Stat returns the FileInfo structure describing file. +// It returns the FileInfo and an error, if any. +func (file *File) Stat() (fi *FileInfo, err Error) { + var stat syscall.Stat_t + e := syscall.Fstat(file.fd, &stat) + if e != 0 { + return nil, &PathError{"stat", file.name, Errno(e)} + } + return fileInfoFromStat(file.name, new(FileInfo), &stat, &stat), nil +} + +// Readdir reads the contents of the directory associated with file and +// returns an array of up to count FileInfo structures, as would be returned +// by Lstat, in directory order. Subsequent calls on the same file will yield +// further FileInfos. +// A negative count means to read until EOF. +// Readdir returns the array and an Error, if any. +func (file *File) Readdir(count int) (fi []FileInfo, err Error) { + dirname := file.name + if dirname == "" { + dirname = "." + } + dirname += "/" + names, err1 := file.Readdirnames(count) + if err1 != nil { + return nil, err1 + } + fi = make([]FileInfo, len(names)) + for i, filename := range names { + fip, err := Lstat(dirname + filename) + if fip == nil || err != nil { + fi[i].Name = filename // rest is already zeroed out + } else { + fi[i] = *fip + } + } + return +} + +// Truncate changes the size of the named file. +// If the file is a symbolic link, it changes the size of the link's target. +func Truncate(name string, size int64) Error { + if e := syscall.Truncate(name, size); e != 0 { + return &PathError{"truncate", name, Errno(e)} + } + return nil +} -- cgit v1.2.3