OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 // The os package provides a platform-independent interface to operating | 5 // The os package provides a platform-independent interface to operating |
6 // system functionality. The design is Unix-like. | 6 // system functionality. The design is Unix-like. |
7 package os | 7 package os |
8 | 8 |
9 import ( | 9 import ( |
10 "runtime" | 10 "runtime" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 ) | 44 ) |
45 | 45 |
46 // Flags to Open wrapping those of the underlying system. Not all flags | 46 // Flags to Open wrapping those of the underlying system. Not all flags |
47 // may be implemented on a given system. | 47 // may be implemented on a given system. |
48 const ( | 48 const ( |
49 O_RDONLY int = syscall.O_RDONLY // open the file read-only. | 49 O_RDONLY int = syscall.O_RDONLY // open the file read-only. |
50 O_WRONLY int = syscall.O_WRONLY // open the file write-only. | 50 O_WRONLY int = syscall.O_WRONLY // open the file write-only. |
51 O_RDWR int = syscall.O_RDWR // open the file read-write. | 51 O_RDWR int = syscall.O_RDWR // open the file read-write. |
52 O_APPEND int = syscall.O_APPEND // append data to the file when writ
ing. | 52 O_APPEND int = syscall.O_APPEND // append data to the file when writ
ing. |
53 O_ASYNC int = syscall.O_ASYNC // generate a signal when I/O is ava
ilable. | 53 O_ASYNC int = syscall.O_ASYNC // generate a signal when I/O is ava
ilable. |
54 » O_CREAT int = syscall.O_CREAT // create a new file if none exists. | 54 » O_CREATE int = syscall.O_CREAT // create a new file if none exists. |
55 » O_EXCL int = syscall.O_EXCL // used with O_CREAT, file must not
exist | 55 » O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not
exist |
56 O_NOCTTY int = syscall.O_NOCTTY // do not make file the controlling
tty. | 56 O_NOCTTY int = syscall.O_NOCTTY // do not make file the controlling
tty. |
57 O_NONBLOCK int = syscall.O_NONBLOCK // open in non-blocking mode. | 57 O_NONBLOCK int = syscall.O_NONBLOCK // open in non-blocking mode. |
58 O_NDELAY int = O_NONBLOCK // synonym for O_NONBLOCK | 58 O_NDELAY int = O_NONBLOCK // synonym for O_NONBLOCK |
59 O_SYNC int = syscall.O_SYNC // open for synchronous I/O. | 59 O_SYNC int = syscall.O_SYNC // open for synchronous I/O. |
60 O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when o
pened. | 60 O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when o
pened. |
61 O_CREATE int = O_CREAT // create a new file if none exists. | |
62 ) | 61 ) |
63 | 62 |
64 // Seek whence values. | 63 // Seek whence values. |
65 const ( | 64 const ( |
66 SEEK_SET int = 0 // seek relative to the origin of the file | 65 SEEK_SET int = 0 // seek relative to the origin of the file |
67 SEEK_CUR int = 1 // seek relative to the current offset | 66 SEEK_CUR int = 1 // seek relative to the current offset |
68 SEEK_END int = 2 // seek relative to the end | 67 SEEK_END int = 2 // seek relative to the end |
69 ) | 68 ) |
70 | 69 |
71 type eofError int | 70 type eofError int |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 207 } |
209 | 208 |
210 // Chdir changes the current working directory to the file, | 209 // Chdir changes the current working directory to the file, |
211 // which must be a directory. | 210 // which must be a directory. |
212 func (f *File) Chdir() Error { | 211 func (f *File) Chdir() Error { |
213 if e := syscall.Fchdir(f.fd); iserror(e) { | 212 if e := syscall.Fchdir(f.fd); iserror(e) { |
214 return &PathError{"chdir", f.name, Errno(e)} | 213 return &PathError{"chdir", f.name, Errno(e)} |
215 } | 214 } |
216 return nil | 215 return nil |
217 } | 216 } |
| 217 |
| 218 // Open opens the named file for reading. If successful, methods on |
| 219 // the returned file can be used for reading; the associated file |
| 220 // descriptor has mode O_RDONLY. |
| 221 // It returns the File and an Error, if any. |
| 222 func Open(name string) (file *File, err Error) { |
| 223 return OpenFile(name, O_RDONLY, 0) |
| 224 } |
| 225 |
| 226 // Create creates the named file mode 0666 (before umask), truncating |
| 227 // it if it already exists. If successful, methods on the returned |
| 228 // File can be used for I/O; the associated file descriptor has mode |
| 229 // O_RDWR. |
| 230 // It returns the File and an Error, if any. |
| 231 func Create(name string) (file *File, err Error) { |
| 232 return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) |
| 233 } |
OLD | NEW |