LEFT | RIGHT |
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Mkdir creates a new directory with the specified name and permission bits. | 209 // Mkdir creates a new directory with the specified name and permission bits. |
210 // It returns an error, if any. | 210 // It returns an error, if any. |
211 func Mkdir(name string, perm int) Error { | 211 func Mkdir(name string, perm int) Error { |
212 e := syscall.Mkdir(name, perm) | 212 e := syscall.Mkdir(name, perm) |
213 if e != 0 { | 213 if e != 0 { |
214 return &PathError{"mkdir", name, Errno(e)} | 214 return &PathError{"mkdir", name, Errno(e)} |
215 } | 215 } |
216 return nil | 216 return nil |
217 } | 217 } |
218 | 218 |
219 // Stat returns a Dir structure describing the named file and an error, if any. | 219 // Stat returns a FileInfo structure describing the named file and an error, if
any. |
220 // If name names a valid symbolic link, the returned Dir describes | 220 // If name names a valid symbolic link, the returned FileInfo describes |
221 // the file pointed at by the link and has dir.FollowedSymlink set to true. | 221 // the file pointed at by the link and has fi.FollowedSymlink set to true. |
222 // If name names an invalid symbolic link, the returned Dir describes | 222 // If name names an invalid symbolic link, the returned FileInfo describes |
223 // the link itself and has dir.FollowedSymlink set to false. | 223 // the link itself and has fi.FollowedSymlink set to false. |
224 func Stat(name string) (dir *Dir, err Error) { | 224 func Stat(name string) (fi *FileInfo, err Error) { |
225 var lstat, stat syscall.Stat_t | 225 var lstat, stat syscall.Stat_t |
226 e := syscall.Lstat(name, &lstat) | 226 e := syscall.Lstat(name, &lstat) |
227 if e != 0 { | 227 if e != 0 { |
228 return nil, &PathError{"stat", name, Errno(e)} | 228 return nil, &PathError{"stat", name, Errno(e)} |
229 } | 229 } |
230 statp := &lstat | 230 statp := &lstat |
231 if lstat.Mode&syscall.S_IFMT == syscall.S_IFLNK { | 231 if lstat.Mode&syscall.S_IFMT == syscall.S_IFLNK { |
232 e := syscall.Stat(name, &stat) | 232 e := syscall.Stat(name, &stat) |
233 if e == 0 { | 233 if e == 0 { |
234 statp = &stat | 234 statp = &stat |
235 } | 235 } |
236 } | 236 } |
237 » return dirFromStat(name, new(Dir), &lstat, statp), nil | 237 » return fileInfoFromStat(name, new(FileInfo), &lstat, statp), nil |
238 } | 238 } |
239 | 239 |
240 // Stat returns the Dir structure describing file. | 240 // Stat returns the FileInfo structure describing file. |
241 // It returns the Dir and an error, if any. | 241 // It returns the FileInfo and an error, if any. |
242 func (file *File) Stat() (dir *Dir, err Error) { | 242 func (file *File) Stat() (fi *FileInfo, err Error) { |
243 var stat syscall.Stat_t | 243 var stat syscall.Stat_t |
244 e := syscall.Fstat(file.fd, &stat) | 244 e := syscall.Fstat(file.fd, &stat) |
245 if e != 0 { | 245 if e != 0 { |
246 return nil, &PathError{"stat", file.name, Errno(e)} | 246 return nil, &PathError{"stat", file.name, Errno(e)} |
247 } | 247 } |
248 » return dirFromStat(file.name, new(Dir), &stat, &stat), nil | 248 » return fileInfoFromStat(file.name, new(FileInfo), &stat, &stat), nil |
249 } | 249 } |
250 | 250 |
251 // Lstat returns the Dir structure describing the named file and an error, if an
y. | 251 // Lstat returns the FileInfo structure describing the named file and an |
252 // If the file is a symbolic link, the returned Dir describes the | 252 // error, if any. If the file is a symbolic link, the returned FileInfo |
253 // symbolic link. Lstat makes no attempt to follow the link. | 253 // describes the symbolic link. Lstat makes no attempt to follow the link. |
254 func Lstat(name string) (dir *Dir, err Error) { | 254 func Lstat(name string) (fi *FileInfo, err Error) { |
255 var stat syscall.Stat_t | 255 var stat syscall.Stat_t |
256 e := syscall.Lstat(name, &stat) | 256 e := syscall.Lstat(name, &stat) |
257 if e != 0 { | 257 if e != 0 { |
258 return nil, &PathError{"lstat", name, Errno(e)} | 258 return nil, &PathError{"lstat", name, Errno(e)} |
259 } | 259 } |
260 » return dirFromStat(name, new(Dir), &stat, &stat), nil | 260 » return fileInfoFromStat(name, new(FileInfo), &stat, &stat), nil |
261 } | 261 } |
262 | 262 |
263 // Chdir changes the current working directory to the named directory. | 263 // Chdir changes the current working directory to the named directory. |
264 func Chdir(dir string) Error { | 264 func Chdir(dir string) Error { |
265 if e := syscall.Chdir(dir); e != 0 { | 265 if e := syscall.Chdir(dir); e != 0 { |
266 return &PathError{"chdir", dir, Errno(e)} | 266 return &PathError{"chdir", dir, Errno(e)} |
267 } | 267 } |
268 return nil | 268 return nil |
269 } | 269 } |
270 | 270 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 // Truncate changes the size of the file. | 419 // Truncate changes the size of the file. |
420 // It does not change the I/O offset. | 420 // It does not change the I/O offset. |
421 func (f *File) Truncate(size int64) Error { | 421 func (f *File) Truncate(size int64) Error { |
422 if e := syscall.Ftruncate(f.fd, size); e != 0 { | 422 if e := syscall.Ftruncate(f.fd, size); e != 0 { |
423 return &PathError{"truncate", f.name, Errno(e)} | 423 return &PathError{"truncate", f.name, Errno(e)} |
424 } | 424 } |
425 return nil | 425 return nil |
426 } | 426 } |
LEFT | RIGHT |