// StartProcess starts a new process with the program, arguments and attributes
// specified by name, argv and attr.
+// If there is an error, it will be of type *PathError.
func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
sysattr := &syscall.ProcAttr{
Dir: attr.Dir,
// named binary, with arguments argv and environment envv.
// If successful, Exec never returns. If it fails, it returns an error.
// ForkExec is almost always a better way to execute a program.
+// If there is an error, it will be of type *PathError.
func Exec(name string, argv []string, envv []string) error {
e := syscall.Exec(name, argv, envv)
if e != nil {
//
// StartProcess is a low-level interface. The os/exec package provides
// higher-level interfaces.
+//
+// If there is an error, it will be of type *PathError.
func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
sysattr := &syscall.ProcAttr{
Dir: attr.Dir,
//
// To run a child process, see StartProcess (for a low-level interface)
// or the os/exec package (for higher-level interfaces).
+//
+// If there is an error, it will be of type *PathError.
func Exec(name string, argv []string, envv []string) error {
if envv == nil {
envv = Environ()
// license that can be found in the LICENSE file.
// Package os provides a platform-independent interface to operating system
-// functionality. The design is Unix-like.
+// functionality. The design is Unix-like, although the error handling is
+// Go-like; failing calls return values of type error rather than error numbers.
+// Often, more information is available within the error. For example,
+// if a call that takes a file name fails, such as Open or Stat, the error
+// will include failing file name when printed and will be of type *PathError,
+// which may be unpacked for more information.
+//
// The os interface is intended to be uniform across all operating systems.
// Features not generally available appear in the system-specific package syscall.
package os
}
// Mkdir creates a new directory with the specified name and permission bits.
-// It returns an error, if any.
+// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error {
e := syscall.Mkdir(name, syscallMode(perm))
if e != nil {
}
// Chdir changes the current working directory to the named directory.
+// If there is an error, it will be of type *PathError.
func Chdir(dir string) error {
if e := syscall.Chdir(dir); e != nil {
return &PathError{"chdir", dir, e}
// Chdir changes the current working directory to the file,
// which must be a directory.
+// If there is an error, it will be of type *PathError.
func (f *File) Chdir() error {
if e := syscall.Fchdir(f.fd); e != nil {
return &PathError{"chdir", f.name, e}
// Open opens the named file for reading. If successful, methods on
// the returned file can be used for reading; the associated file
// descriptor has mode O_RDONLY.
-// It returns the File and an error, if any.
+// If there is an error, it will be of type *PathError.
func Open(name string) (file *File, err error) {
return OpenFile(name, O_RDONLY, 0)
}
// it if it already exists. If successful, methods on the returned
// File can be used for I/O; the associated file descriptor has mode
// O_RDWR.
-// It returns the File and an error, if any.
+// If there is an error, it will be of type *PathError.
func Create(name string) (file *File, err error) {
return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
}
// or Create instead. It 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.
+// If there is an error, it will be of type *PathError.
func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
var (
fd int
const chmodMask = uint32(syscall.DMAPPEND | syscall.DMEXCL | syscall.DMTMP | ModePerm)
// Chmod changes the mode of the file to mode.
+// If there is an error, it will be of type *PathError.
func (f *File) Chmod(mode FileMode) error {
var d Dir
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
+// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
var d Dir
d.Null()
}
// Remove removes the named file or directory.
+// If there is an error, it will be of type *PathError.
func Remove(name string) error {
if e := syscall.Remove(name); e != nil {
return &PathError{"remove", name, e}
}
// Rename renames a file.
+// If there is an error, it will be of type *PathError.
func Rename(oldname, newname string) error {
var d Dir
d.Null()
}
// Chmod changes the mode of the named file to mode.
+// If there is an error, it will be of type *PathError.
func Chmod(name string, mode FileMode) error {
var d Dir
// Readlink reads the contents of a symbolic link: the destination of
// the link. It returns the contents and an error, if any.
+// If there is an error, it will be of type *PathError.
func Readlink(name string) (string, error) {
for len := 128; ; len *= 2 {
b := make([]byte, len)
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
+// If there is an error, it will be of type *PathError.
func Chmod(name string, mode FileMode) error {
if e := syscall.Chmod(name, syscallMode(mode)); e != nil {
return &PathError{"chmod", name, e}
}
// Chmod changes the mode of the file to mode.
+// If there is an error, it will be of type *PathError.
func (f *File) Chmod(mode FileMode) error {
if e := syscall.Fchmod(f.fd, syscallMode(mode)); e != nil {
return &PathError{"chmod", f.name, e}
// Chown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link's target.
+// If there is an error, it will be of type *PathError.
func Chown(name string, uid, gid int) error {
if e := syscall.Chown(name, uid, gid); e != nil {
return &PathError{"chown", name, e}
// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
+// If there is an error, it will be of type *PathError.
func Lchown(name string, uid, gid int) error {
if e := syscall.Lchown(name, uid, gid); e != nil {
return &PathError{"lchown", name, e}
}
// Chown changes the numeric uid and gid of the named file.
+// If there is an error, it will be of type *PathError.
func (f *File) Chown(uid, gid int) error {
if e := syscall.Fchown(f.fd, uid, gid); e != nil {
return &PathError{"chown", f.name, e}
// Truncate changes the size of the file.
// It does not change the I/O offset.
+// If there is an error, it will be of type *PathError.
func (f *File) Truncate(size int64) error {
if e := syscall.Ftruncate(f.fd, size); e != nil {
return &PathError{"truncate", f.name, e}
//
// The underlying filesystem may truncate or round the values to a
// less precise time unit.
+// If there is an error, it will be of type *PathError.
func Chtimes(name string, atime time.Time, mtime time.Time) error {
var utimes [2]syscall.Timeval
atime_ns := atime.Unix()*1e9 + int64(atime.Nanosecond())
// or Create instead. It 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.
+// If there is an error, it will be of type *PathError.
func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
r, e := syscall.Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm))
if e != nil {
}
// Stat returns the FileInfo structure describing file.
-// It returns the FileInfo and an error, if any.
+// If there is an error, it will be of type *PathError.
func (f *File) Stat() (fi FileInfo, err error) {
var stat syscall.Stat_t
err = syscall.Fstat(f.fd, &stat)
return fileInfoFromStat(&stat, f.name), nil
}
-// Stat returns a FileInfo describing the named file and an error, if any.
+// Stat returns a FileInfo describing the named file.
// If name names a valid symbolic link, the returned FileInfo describes
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// If name names an invalid symbolic link, the returned FileInfo describes
// the link itself and has fi.FollowedSymlink set to false.
+// If there is an error, it will be of type *PathError.
func Stat(name string) (fi FileInfo, err error) {
var stat syscall.Stat_t
err = syscall.Stat(name, &stat)
return fileInfoFromStat(&stat, name), nil
}
-// Lstat returns a FileInfo describing the named file and an
-// error, if any. If the file is a symbolic link, the returned FileInfo
+// Lstat returns a FileInfo describing the named file.
+// If the file is a symbolic link, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
+// If there is an error, it will be of type *PathError.
func Lstat(name string) (fi FileInfo, err error) {
var stat syscall.Stat_t
err = syscall.Lstat(name, &stat)
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
+// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
if e := syscall.Truncate(name, size); e != nil {
return &PathError{"truncate", name, e}
}
// Remove removes the named file or directory.
+// If there is an error, it will be of type *PathError.
func Remove(name string) error {
// System call interface forces us to know
// whether name is a file or directory.
// or Create instead. It 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.
+// If there is an error, it will be of type *PathError.
func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
if name == "" {
return nil, &PathError{"open", name, syscall.ENOENT}
}
// Remove removes the named file or directory.
+// If there is an error, it will be of type *PathError.
func Remove(name string) error {
p := &syscall.StringToUTF16(name)[0]
return nil, &PathError{"stat", name, Ebadstat}
}
-// Stat returns a FileInfo structure describing the named file and an error, if any.
+// Stat returns a FileInfo structure describing the named file.
+// If there is an error, it will be of type *PathError.
func Stat(name string) (FileInfo, error) {
d, err := dirstat(name)
if err != nil {
return fileInfoFromStat(d), nil
}
-// Lstat returns the FileInfo structure describing the named file and an
-// error, if any. If the file is a symbolic link (though Plan 9 does not have symbolic links),
+// Lstat returns the FileInfo structure describing the named file.
+// If the file is a symbolic link (though Plan 9 does not have symbolic links),
// the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
+// If there is an error, it will be of type *PathError.
func Lstat(name string) (FileInfo, error) {
return Stat(name)
}
)
// Stat returns the FileInfo structure describing file.
-// It returns the FileInfo and an error, if any.
+// If there is an error, it will be of type *PathError.
func (file *File) Stat() (fi FileInfo, err error) {
if file == nil || file.fd < 0 {
return nil, EINVAL
return toFileInfo(basename(file.name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), nil
}
-// Stat returns a FileInfo structure describing the named file and an error, if any.
+// Stat returns a FileInfo structure describing the named file.
// If name names a valid symbolic link, the returned FileInfo describes
// the file pointed at by the link and has fi.FollowedSymlink set to true.
// If name names an invalid symbolic link, the returned FileInfo describes
// the link itself and has fi.FollowedSymlink set to false.
+// If there is an error, it will be of type *PathError.
func Stat(name string) (fi FileInfo, err error) {
if len(name) == 0 {
return nil, &PathError{"Stat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
return toFileInfo(basename(name), d.FileAttributes, d.FileSizeHigh, d.FileSizeLow, d.CreationTime, d.LastAccessTime, d.LastWriteTime), nil
}
-// Lstat returns the FileInfo structure describing the named file and an
-// error, if any. If the file is a symbolic link, the returned FileInfo
+// Lstat returns the FileInfo structure describing the named file.
+// If the file is a symbolic link, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
+// If there is an error, it will be of type *PathError.
func Lstat(name string) (fi FileInfo, err error) {
// No links on Windows
return Stat(name)