~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/os/file_unix.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "syscall"
10
10
)
11
11
 
 
12
// File represents an open file descriptor.
 
13
type File struct {
 
14
        fd      int
 
15
        name    string
 
16
        dirinfo *dirInfo // nil unless directory being read
 
17
        nepipe  int      // number of consecutive EPIPE in Write
 
18
}
 
19
 
 
20
// Fd returns the integer Unix file descriptor referencing the open file.
 
21
func (file *File) Fd() int {
 
22
        if file == nil {
 
23
                return -1
 
24
        }
 
25
        return file.fd
 
26
}
 
27
 
 
28
// NewFile returns a new File with the given file descriptor and name.
 
29
func NewFile(fd int, name string) *File {
 
30
        if fd < 0 {
 
31
                return nil
 
32
        }
 
33
        f := &File{fd: fd, name: name}
 
34
        runtime.SetFinalizer(f, (*File).Close)
 
35
        return f
 
36
}
 
37
 
12
38
// Auxiliary information if the File describes a directory
13
39
type dirInfo struct {
14
40
        buf  []byte // buffer for directory I/O
161
187
 
162
188
        return name
163
189
}
 
190
 
 
191
// Pipe returns a connected pair of Files; reads from r return bytes written to w.
 
192
// It returns the files and an Error, if any.
 
193
func Pipe() (r *File, w *File, err Error) {
 
194
        var p [2]int
 
195
 
 
196
        // See ../syscall/exec.go for description of lock.
 
197
        syscall.ForkLock.RLock()
 
198
        e := syscall.Pipe(p[0:])
 
199
        if iserror(e) {
 
200
                syscall.ForkLock.RUnlock()
 
201
                return nil, nil, NewSyscallError("pipe", e)
 
202
        }
 
203
        syscall.CloseOnExec(p[0])
 
204
        syscall.CloseOnExec(p[1])
 
205
        syscall.ForkLock.RUnlock()
 
206
 
 
207
        return NewFile(p[0], "|0"), NewFile(p[1], "|1"), nil
 
208
}