OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package os | 5 package os |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
| 9 "sync" |
9 "syscall" | 10 "syscall" |
10 ) | 11 ) |
11 | 12 |
| 13 // File represents an open file descriptor. |
| 14 type File struct { |
| 15 fd int |
| 16 name string |
| 17 dirinfo *dirInfo // nil unless directory being read |
| 18 nepipe int // number of consecutive EPIPE in Write |
| 19 l sync.Mutex // used to implement windows pread/pwrite |
| 20 } |
| 21 |
| 22 // Fd returns the integer Unix file descriptor referencing the open file. |
| 23 func (file *File) Fd() int { |
| 24 if file == nil { |
| 25 return -1 |
| 26 } |
| 27 return file.fd |
| 28 } |
| 29 |
| 30 // NewFile returns a new File with the given file descriptor and name. |
| 31 func NewFile(fd int, name string) *File { |
| 32 if fd < 0 { |
| 33 return nil |
| 34 } |
| 35 f := &File{fd: fd, name: name} |
| 36 runtime.SetFinalizer(f, (*File).Close) |
| 37 return f |
| 38 } |
| 39 |
12 // Auxiliary information if the File describes a directory | 40 // Auxiliary information if the File describes a directory |
13 type dirInfo struct { | 41 type dirInfo struct { |
14 buf [syscall.STATMAX]byte // buffer for directory I/O | 42 buf [syscall.STATMAX]byte // buffer for directory I/O |
15 nbuf int // length of buf; return value from Read | 43 nbuf int // length of buf; return value from Read |
16 bufp int // location of next record in buf. | 44 bufp int // location of next record in buf. |
17 } | 45 } |
18 | 46 |
19 func epipecheck(file *File, e syscall.Error) { | 47 func epipecheck(file *File, e syscall.Error) { |
20 } | 48 } |
21 | 49 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return EPLAN9 | 341 return EPLAN9 |
314 } | 342 } |
315 | 343 |
316 func Lchown(name string, uid, gid int) Error { | 344 func Lchown(name string, uid, gid int) Error { |
317 return EPLAN9 | 345 return EPLAN9 |
318 } | 346 } |
319 | 347 |
320 func (f *File) Chown(uid, gid int) Error { | 348 func (f *File) Chown(uid, gid int) Error { |
321 return EPLAN9 | 349 return EPLAN9 |
322 } | 350 } |
OLD | NEW |