summaryrefslogtreecommitdiff
path: root/devdocs/go/os%2Findex.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/go/os%2Findex.html
new repository
Diffstat (limited to 'devdocs/go/os%2Findex.html')
-rw-r--r--devdocs/go/os%2Findex.html787
1 files changed, 787 insertions, 0 deletions
diff --git a/devdocs/go/os%2Findex.html b/devdocs/go/os%2Findex.html
new file mode 100644
index 00000000..148102b9
--- /dev/null
+++ b/devdocs/go/os%2Findex.html
@@ -0,0 +1,787 @@
+<h1> Package os </h1> <ul id="short-nav">
+<li><code>import "os"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+<li><a href="#pkg-subdirectories">Subdirectories</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package os provides a platform-independent interface to operating system 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 the failing file name when printed and will be of type *PathError, which may be unpacked for more information. </p>
+<p>The os interface is intended to be uniform across all operating systems. Features not generally available appear in the system-specific package syscall. </p>
+<p>Here is a simple example, opening a file and reading some of it. </p>
+<pre data-language="go">file, err := os.Open("file.go") // For read access.
+if err != nil {
+ log.Fatal(err)
+}
+</pre> <p>If the open fails, the error string will be self-explanatory, like </p>
+<pre data-language="go">open file.go: no such file or directory
+</pre> <p>The file's data can then be read into a slice of bytes. Read and Write take their byte counts from the length of the argument slice. </p>
+<pre data-language="go">data := make([]byte, 100)
+count, err := file.Read(data)
+if err != nil {
+ log.Fatal(err)
+}
+fmt.Printf("read %d bytes: %q\n", count, data[:count])
+</pre> <p>Note: The maximum number of concurrent operations on a File may be limited by the OS or the system. The number should be high, but exceeding it may degrade performance or cause other issues. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#pkg-constants">Constants</a></li>
+<li><a href="#pkg-variables">Variables</a></li>
+<li><a href="#Chdir">func Chdir(dir string) error</a></li>
+<li><a href="#Chmod">func Chmod(name string, mode FileMode) error</a></li>
+<li><a href="#Chown">func Chown(name string, uid, gid int) error</a></li>
+<li><a href="#Chtimes">func Chtimes(name string, atime time.Time, mtime time.Time) error</a></li>
+<li><a href="#Clearenv">func Clearenv()</a></li>
+<li><a href="#DirFS">func DirFS(dir string) fs.FS</a></li>
+<li><a href="#Environ">func Environ() []string</a></li>
+<li><a href="#Executable">func Executable() (string, error)</a></li>
+<li><a href="#Exit">func Exit(code int)</a></li>
+<li><a href="#Expand">func Expand(s string, mapping func(string) string) string</a></li>
+<li><a href="#ExpandEnv">func ExpandEnv(s string) string</a></li>
+<li><a href="#Getegid">func Getegid() int</a></li>
+<li><a href="#Getenv">func Getenv(key string) string</a></li>
+<li><a href="#Geteuid">func Geteuid() int</a></li>
+<li><a href="#Getgid">func Getgid() int</a></li>
+<li><a href="#Getgroups">func Getgroups() ([]int, error)</a></li>
+<li><a href="#Getpagesize">func Getpagesize() int</a></li>
+<li><a href="#Getpid">func Getpid() int</a></li>
+<li><a href="#Getppid">func Getppid() int</a></li>
+<li><a href="#Getuid">func Getuid() int</a></li>
+<li><a href="#Getwd">func Getwd() (dir string, err error)</a></li>
+<li><a href="#Hostname">func Hostname() (name string, err error)</a></li>
+<li><a href="#IsExist">func IsExist(err error) bool</a></li>
+<li><a href="#IsNotExist">func IsNotExist(err error) bool</a></li>
+<li><a href="#IsPathSeparator">func IsPathSeparator(c uint8) bool</a></li>
+<li><a href="#IsPermission">func IsPermission(err error) bool</a></li>
+<li><a href="#IsTimeout">func IsTimeout(err error) bool</a></li>
+<li><a href="#Lchown">func Lchown(name string, uid, gid int) error</a></li>
+<li><a href="#Link">func Link(oldname, newname string) error</a></li>
+<li><a href="#LookupEnv">func LookupEnv(key string) (string, bool)</a></li>
+<li><a href="#Mkdir">func Mkdir(name string, perm FileMode) error</a></li>
+<li><a href="#MkdirAll">func MkdirAll(path string, perm FileMode) error</a></li>
+<li><a href="#MkdirTemp">func MkdirTemp(dir, pattern string) (string, error)</a></li>
+<li><a href="#NewSyscallError">func NewSyscallError(syscall string, err error) error</a></li>
+<li><a href="#Pipe">func Pipe() (r *File, w *File, err error)</a></li>
+<li><a href="#ReadFile">func ReadFile(name string) ([]byte, error)</a></li>
+<li><a href="#Readlink">func Readlink(name string) (string, error)</a></li>
+<li><a href="#Remove">func Remove(name string) error</a></li>
+<li><a href="#RemoveAll">func RemoveAll(path string) error</a></li>
+<li><a href="#Rename">func Rename(oldpath, newpath string) error</a></li>
+<li><a href="#SameFile">func SameFile(fi1, fi2 FileInfo) bool</a></li>
+<li><a href="#Setenv">func Setenv(key, value string) error</a></li>
+<li><a href="#Symlink">func Symlink(oldname, newname string) error</a></li>
+<li><a href="#TempDir">func TempDir() string</a></li>
+<li><a href="#Truncate">func Truncate(name string, size int64) error</a></li>
+<li><a href="#Unsetenv">func Unsetenv(key string) error</a></li>
+<li><a href="#UserCacheDir">func UserCacheDir() (string, error)</a></li>
+<li><a href="#UserConfigDir">func UserConfigDir() (string, error)</a></li>
+<li><a href="#UserHomeDir">func UserHomeDir() (string, error)</a></li>
+<li><a href="#WriteFile">func WriteFile(name string, data []byte, perm FileMode) error</a></li>
+<li><a href="#DirEntry">type DirEntry</a></li>
+<li> <a href="#ReadDir">func ReadDir(name string) ([]DirEntry, error)</a>
+</li>
+<li><a href="#File">type File</a></li>
+<li> <a href="#Create">func Create(name string) (*File, error)</a>
+</li>
+<li> <a href="#CreateTemp">func CreateTemp(dir, pattern string) (*File, error)</a>
+</li>
+<li> <a href="#NewFile">func NewFile(fd uintptr, name string) *File</a>
+</li>
+<li> <a href="#Open">func Open(name string) (*File, error)</a>
+</li>
+<li> <a href="#OpenFile">func OpenFile(name string, flag int, perm FileMode) (*File, error)</a>
+</li>
+<li> <a href="#File.Chdir">func (f *File) Chdir() error</a>
+</li>
+<li> <a href="#File.Chmod">func (f *File) Chmod(mode FileMode) error</a>
+</li>
+<li> <a href="#File.Chown">func (f *File) Chown(uid, gid int) error</a>
+</li>
+<li> <a href="#File.Close">func (f *File) Close() error</a>
+</li>
+<li> <a href="#File.Fd">func (f *File) Fd() uintptr</a>
+</li>
+<li> <a href="#File.Name">func (f *File) Name() string</a>
+</li>
+<li> <a href="#File.Read">func (f *File) Read(b []byte) (n int, err error)</a>
+</li>
+<li> <a href="#File.ReadAt">func (f *File) ReadAt(b []byte, off int64) (n int, err error)</a>
+</li>
+<li> <a href="#File.ReadDir">func (f *File) ReadDir(n int) ([]DirEntry, error)</a>
+</li>
+<li> <a href="#File.ReadFrom">func (f *File) ReadFrom(r io.Reader) (n int64, err error)</a>
+</li>
+<li> <a href="#File.Readdir">func (f *File) Readdir(n int) ([]FileInfo, error)</a>
+</li>
+<li> <a href="#File.Readdirnames">func (f *File) Readdirnames(n int) (names []string, err error)</a>
+</li>
+<li> <a href="#File.Seek">func (f *File) Seek(offset int64, whence int) (ret int64, err error)</a>
+</li>
+<li> <a href="#File.SetDeadline">func (f *File) SetDeadline(t time.Time) error</a>
+</li>
+<li> <a href="#File.SetReadDeadline">func (f *File) SetReadDeadline(t time.Time) error</a>
+</li>
+<li> <a href="#File.SetWriteDeadline">func (f *File) SetWriteDeadline(t time.Time) error</a>
+</li>
+<li> <a href="#File.Stat">func (f *File) Stat() (FileInfo, error)</a>
+</li>
+<li> <a href="#File.Sync">func (f *File) Sync() error</a>
+</li>
+<li> <a href="#File.SyscallConn">func (f *File) SyscallConn() (syscall.RawConn, error)</a>
+</li>
+<li> <a href="#File.Truncate">func (f *File) Truncate(size int64) error</a>
+</li>
+<li> <a href="#File.Write">func (f *File) Write(b []byte) (n int, err error)</a>
+</li>
+<li> <a href="#File.WriteAt">func (f *File) WriteAt(b []byte, off int64) (n int, err error)</a>
+</li>
+<li> <a href="#File.WriteString">func (f *File) WriteString(s string) (n int, err error)</a>
+</li>
+<li> <a href="#File.WriteTo">func (f *File) WriteTo(w io.Writer) (n int64, err error)</a>
+</li>
+<li><a href="#FileInfo">type FileInfo</a></li>
+<li> <a href="#Lstat">func Lstat(name string) (FileInfo, error)</a>
+</li>
+<li> <a href="#Stat">func Stat(name string) (FileInfo, error)</a>
+</li>
+<li><a href="#FileMode">type FileMode</a></li>
+<li><a href="#LinkError">type LinkError</a></li>
+<li> <a href="#LinkError.Error">func (e *LinkError) Error() string</a>
+</li>
+<li> <a href="#LinkError.Unwrap">func (e *LinkError) Unwrap() error</a>
+</li>
+<li><a href="#PathError">type PathError</a></li>
+<li><a href="#ProcAttr">type ProcAttr</a></li>
+<li><a href="#Process">type Process</a></li>
+<li> <a href="#FindProcess">func FindProcess(pid int) (*Process, error)</a>
+</li>
+<li> <a href="#StartProcess">func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)</a>
+</li>
+<li> <a href="#Process.Kill">func (p *Process) Kill() error</a>
+</li>
+<li> <a href="#Process.Release">func (p *Process) Release() error</a>
+</li>
+<li> <a href="#Process.Signal">func (p *Process) Signal(sig Signal) error</a>
+</li>
+<li> <a href="#Process.Wait">func (p *Process) Wait() (*ProcessState, error)</a>
+</li>
+<li><a href="#ProcessState">type ProcessState</a></li>
+<li> <a href="#ProcessState.ExitCode">func (p *ProcessState) ExitCode() int</a>
+</li>
+<li> <a href="#ProcessState.Exited">func (p *ProcessState) Exited() bool</a>
+</li>
+<li> <a href="#ProcessState.Pid">func (p *ProcessState) Pid() int</a>
+</li>
+<li> <a href="#ProcessState.String">func (p *ProcessState) String() string</a>
+</li>
+<li> <a href="#ProcessState.Success">func (p *ProcessState) Success() bool</a>
+</li>
+<li> <a href="#ProcessState.Sys">func (p *ProcessState) Sys() any</a>
+</li>
+<li> <a href="#ProcessState.SysUsage">func (p *ProcessState) SysUsage() any</a>
+</li>
+<li> <a href="#ProcessState.SystemTime">func (p *ProcessState) SystemTime() time.Duration</a>
+</li>
+<li> <a href="#ProcessState.UserTime">func (p *ProcessState) UserTime() time.Duration</a>
+</li>
+<li><a href="#Signal">type Signal</a></li>
+<li><a href="#SyscallError">type SyscallError</a></li>
+<li> <a href="#SyscallError.Error">func (e *SyscallError) Error() string</a>
+</li>
+<li> <a href="#SyscallError.Timeout">func (e *SyscallError) Timeout() bool</a>
+</li>
+<li> <a href="#SyscallError.Unwrap">func (e *SyscallError) Unwrap() error</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Chmod">Chmod</a></dd> <dd><a class="exampleLink" href="#example_Chtimes">Chtimes</a></dd> <dd><a class="exampleLink" href="#example_CreateTemp">CreateTemp</a></dd> <dd><a class="exampleLink" href="#example_CreateTemp_suffix">CreateTemp (Suffix)</a></dd> <dd><a class="exampleLink" href="#example_ErrNotExist">ErrNotExist</a></dd> <dd><a class="exampleLink" href="#example_Expand">Expand</a></dd> <dd><a class="exampleLink" href="#example_ExpandEnv">ExpandEnv</a></dd> <dd><a class="exampleLink" href="#example_FileMode">FileMode</a></dd> <dd><a class="exampleLink" href="#example_Getenv">Getenv</a></dd> <dd><a class="exampleLink" href="#example_LookupEnv">LookupEnv</a></dd> <dd><a class="exampleLink" href="#example_Mkdir">Mkdir</a></dd> <dd><a class="exampleLink" href="#example_MkdirAll">MkdirAll</a></dd> <dd><a class="exampleLink" href="#example_MkdirTemp">MkdirTemp</a></dd> <dd><a class="exampleLink" href="#example_MkdirTemp_suffix">MkdirTemp (Suffix)</a></dd> <dd><a class="exampleLink" href="#example_OpenFile">OpenFile</a></dd> <dd><a class="exampleLink" href="#example_OpenFile_append">OpenFile (Append)</a></dd> <dd><a class="exampleLink" href="#example_ReadDir">ReadDir</a></dd> <dd><a class="exampleLink" href="#example_ReadFile">ReadFile</a></dd> <dd><a class="exampleLink" href="#example_Readlink">Readlink</a></dd> <dd><a class="exampleLink" href="#example_Unsetenv">Unsetenv</a></dd> <dd><a class="exampleLink" href="#example_UserCacheDir">UserCacheDir</a></dd> <dd><a class="exampleLink" href="#example_UserConfigDir">UserConfigDir</a></dd> <dd><a class="exampleLink" href="#example_WriteFile">WriteFile</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>dir.go</span> <span>dir_unix.go</span> <span>dirent_linux.go</span> <span>endian_little.go</span> <span>env.go</span> <span>error.go</span> <span>error_errno.go</span> <span>error_posix.go</span> <span>exec.go</span> <span>exec_posix.go</span> <span>exec_unix.go</span> <span>executable.go</span> <span>executable_procfs.go</span> <span>file.go</span> <span>file_open_unix.go</span> <span>file_posix.go</span> <span>file_unix.go</span> <span>getwd.go</span> <span>path.go</span> <span>path_unix.go</span> <span>pipe2_unix.go</span> <span>proc.go</span> <span>rawconn.go</span> <span>removeall_at.go</span> <span>stat.go</span> <span>stat_linux.go</span> <span>stat_unix.go</span> <span>sticky_notbsd.go</span> <span>sys.go</span> <span>sys_linux.go</span> <span>sys_unix.go</span> <span>tempfile.go</span> <span>types.go</span> <span>types_unix.go</span> <span>wait_waitid.go</span> <span>zero_copy_linux.go</span> </p> <h2 id="pkg-constants">Constants</h2> <p>Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system. </p>
+<pre data-language="go">const (
+ // Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
+ O_RDONLY int = syscall.O_RDONLY // open the file read-only.
+ O_WRONLY int = syscall.O_WRONLY // open the file write-only.
+ O_RDWR int = syscall.O_RDWR // open the file read-write.
+ // The remaining values may be or'ed in to control behavior.
+ O_APPEND int = syscall.O_APPEND // append data to the file when writing.
+ O_CREATE int = syscall.O_CREAT // create a new file if none exists.
+ O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist.
+ O_SYNC int = syscall.O_SYNC // open for synchronous I/O.
+ O_TRUNC int = syscall.O_TRUNC // truncate regular writable file when opened.
+)</pre> <p>Seek whence values. </p>
+<p>Deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd. </p>
+<pre data-language="go">const (
+ SEEK_SET int = 0 // seek relative to the origin of the file
+ SEEK_CUR int = 1 // seek relative to the current offset
+ SEEK_END int = 2 // seek relative to the end
+)</pre> <pre data-language="go">const (
+ PathSeparator = '/' // OS-specific path separator
+ PathListSeparator = ':' // OS-specific path list separator
+)</pre> <p>The defined file mode bits are the most significant bits of the FileMode. The nine least-significant bits are the standard Unix rwxrwxrwx permissions. The values of these bits should be considered part of the public API and may be used in wire protocols or disk representations: they must not be changed, although new bits might be added. </p>
+<pre data-language="go">const (
+ // The single letters are the abbreviations
+ // used by the String method's formatting.
+ ModeDir = fs.ModeDir // d: is a directory
+ ModeAppend = fs.ModeAppend // a: append-only
+ ModeExclusive = fs.ModeExclusive // l: exclusive use
+ ModeTemporary = fs.ModeTemporary // T: temporary file; Plan 9 only
+ ModeSymlink = fs.ModeSymlink // L: symbolic link
+ ModeDevice = fs.ModeDevice // D: device file
+ ModeNamedPipe = fs.ModeNamedPipe // p: named pipe (FIFO)
+ ModeSocket = fs.ModeSocket // S: Unix domain socket
+ ModeSetuid = fs.ModeSetuid // u: setuid
+ ModeSetgid = fs.ModeSetgid // g: setgid
+ ModeCharDevice = fs.ModeCharDevice // c: Unix character device, when ModeDevice is set
+ ModeSticky = fs.ModeSticky // t: sticky
+ ModeIrregular = fs.ModeIrregular // ?: non-regular file; nothing else is known about this file
+
+ // Mask for the type bits. For regular files, none will be set.
+ ModeType = fs.ModeType
+
+ ModePerm = fs.ModePerm // Unix permission bits, 0o777
+)</pre> <p>DevNull is the name of the operating system's “null device.” On Unix-like systems, it is "/dev/null"; on Windows, "NUL". </p>
+<pre data-language="go">const DevNull = "/dev/null"</pre> <h2 id="pkg-variables">Variables</h2> <p>Portable analogs of some common system call errors. </p>
+<p>Errors returned from this package may be tested against these errors with errors.Is. </p>
+<pre data-language="go">var (
+ // ErrInvalid indicates an invalid argument.
+ // Methods on File will return this error when the receiver is nil.
+ ErrInvalid = fs.ErrInvalid // "invalid argument"
+
+ ErrPermission = fs.ErrPermission // "permission denied"
+ ErrExist = fs.ErrExist // "file already exists"
+ ErrNotExist = fs.ErrNotExist // "file does not exist"
+ ErrClosed = fs.ErrClosed // "file already closed"
+
+ ErrNoDeadline = errNoDeadline() // "file type does not support deadline"
+ ErrDeadlineExceeded = errDeadlineExceeded() // "i/o timeout"
+)</pre> <p>Stdin, Stdout, and Stderr are open Files pointing to the standard input, standard output, and standard error file descriptors. </p>
+<p>Note that the Go runtime writes to standard error for panics and crashes; closing Stderr may cause those messages to go elsewhere, perhaps to a file opened later. </p>
+<pre data-language="go">var (
+ Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
+ Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
+ Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
+)</pre> <p>Args hold the command-line arguments, starting with the program name. </p>
+<pre data-language="go">var Args []string</pre> <p>ErrProcessDone indicates a Process has finished. </p>
+<pre data-language="go">var ErrProcessDone = errors.New("os: process already finished")</pre> <h2 id="Chdir">func <span>Chdir</span> </h2> <pre data-language="go">func Chdir(dir string) error</pre> <p>Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError. </p>
+<h2 id="Chmod">func <span>Chmod</span> </h2> <pre data-language="go">func Chmod(name string, mode FileMode) error</pre> <p>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. </p>
+<p>A different subset of the mode bits are used, depending on the operating system. </p>
+<p>On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used. </p>
+<p>On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file. </p>
+<p>On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used. </p> <h4 id="example_Chmod"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+if err := os.Chmod("some-filename", 0644); err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="Chown">func <span>Chown</span> </h2> <pre data-language="go">func Chown(name string, uid, gid int) error</pre> <p>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. A uid or gid of -1 means to not change that value. If there is an error, it will be of type *PathError. </p>
+<p>On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or EPLAN9 error, wrapped in *PathError. </p>
+<h2 id="Chtimes">func <span>Chtimes</span> </h2> <pre data-language="go">func Chtimes(name string, atime time.Time, mtime time.Time) error</pre> <p>Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions. A zero time.Time value will leave the corresponding file time unchanged. </p>
+<p>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. </p> <h4 id="example_Chtimes"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+mtime := time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC)
+atime := time.Date(2007, time.March, 2, 4, 5, 6, 0, time.UTC)
+if err := os.Chtimes("some-filename", atime, mtime); err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="Clearenv">func <span>Clearenv</span> </h2> <pre data-language="go">func Clearenv()</pre> <p>Clearenv deletes all environment variables. </p>
+<h2 id="DirFS">func <span>DirFS</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func DirFS(dir string) fs.FS</pre> <p>DirFS returns a file system (an fs.FS) for the tree of files rooted at the directory dir. </p>
+<p>Note that DirFS("/prefix") only guarantees that the Open calls it makes to the operating system will begin with "/prefix": DirFS("/prefix").Open("file") is the same as os.Open("/prefix/file"). So if /prefix/file is a symbolic link pointing outside the /prefix tree, then using DirFS does not stop the access any more than using os.Open does. Additionally, the root of the fs.FS returned for a relative path, DirFS("prefix"), will be affected by later calls to Chdir. DirFS is therefore not a general substitute for a chroot-style security mechanism when the directory tree contains arbitrary content. </p>
+<p>The directory dir must not be "". </p>
+<p>The result implements <span>io/fs.StatFS</span>, <span>io/fs.ReadFileFS</span> and <span>io/fs.ReadDirFS</span>. </p>
+<h2 id="Environ">func <span>Environ</span> </h2> <pre data-language="go">func Environ() []string</pre> <p>Environ returns a copy of strings representing the environment, in the form "key=value". </p>
+<h2 id="Executable">func <span>Executable</span> <span title="Added in Go 1.8">1.8</span> </h2> <pre data-language="go">func Executable() (string, error)</pre> <p>Executable returns the path name for the executable that started the current process. There is no guarantee that the path is still pointing to the correct executable. If a symlink was used to start the process, depending on the operating system, the result might be the symlink or the path it pointed to. If a stable result is needed, path/filepath.EvalSymlinks might help. </p>
+<p>Executable returns an absolute path unless an error occurred. </p>
+<p>The main use case is finding resources located relative to an executable. </p>
+<h2 id="Exit">func <span>Exit</span> </h2> <pre data-language="go">func Exit(code int)</pre> <p>Exit causes the current program to exit with the given status code. Conventionally, code zero indicates success, non-zero an error. The program terminates immediately; deferred functions are not run. </p>
+<p>For portability, the status code should be in the range [0, 125]. </p>
+<h2 id="Expand">func <span>Expand</span> </h2> <pre data-language="go">func Expand(s string, mapping func(string) string) string</pre> <p>Expand replaces ${var} or $var in the string based on the mapping function. For example, os.ExpandEnv(s) is equivalent to os.Expand(s, os.Getenv). </p> <h4 id="example_Expand"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">mapper := func(placeholderName string) string {
+ switch placeholderName {
+ case "DAY_PART":
+ return "morning"
+ case "NAME":
+ return "Gopher"
+ }
+
+ return ""
+}
+
+fmt.Println(os.Expand("Good ${DAY_PART}, $NAME!", mapper))
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">Good morning, Gopher!
+</pre> <h2 id="ExpandEnv">func <span>ExpandEnv</span> </h2> <pre data-language="go">func ExpandEnv(s string) string</pre> <p>ExpandEnv replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string. </p> <h4 id="example_ExpandEnv"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">os.Setenv("NAME", "gopher")
+os.Setenv("BURROW", "/usr/gopher")
+
+fmt.Println(os.ExpandEnv("$NAME lives in ${BURROW}."))
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">gopher lives in /usr/gopher.
+</pre> <h2 id="Getegid">func <span>Getegid</span> </h2> <pre data-language="go">func Getegid() int</pre> <p>Getegid returns the numeric effective group id of the caller. </p>
+<p>On Windows, it returns -1. </p>
+<h2 id="Getenv">func <span>Getenv</span> </h2> <pre data-language="go">func Getenv(key string) string</pre> <p>Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. To distinguish between an empty value and an unset value, use LookupEnv. </p> <h4 id="example_Getenv"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">os.Setenv("NAME", "gopher")
+os.Setenv("BURROW", "/usr/gopher")
+
+fmt.Printf("%s lives in %s.\n", os.Getenv("NAME"), os.Getenv("BURROW"))
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">gopher lives in /usr/gopher.
+</pre> <h2 id="Geteuid">func <span>Geteuid</span> </h2> <pre data-language="go">func Geteuid() int</pre> <p>Geteuid returns the numeric effective user id of the caller. </p>
+<p>On Windows, it returns -1. </p>
+<h2 id="Getgid">func <span>Getgid</span> </h2> <pre data-language="go">func Getgid() int</pre> <p>Getgid returns the numeric group id of the caller. </p>
+<p>On Windows, it returns -1. </p>
+<h2 id="Getgroups">func <span>Getgroups</span> </h2> <pre data-language="go">func Getgroups() ([]int, error)</pre> <p>Getgroups returns a list of the numeric ids of groups that the caller belongs to. </p>
+<p>On Windows, it returns syscall.EWINDOWS. See the os/user package for a possible alternative. </p>
+<h2 id="Getpagesize">func <span>Getpagesize</span> </h2> <pre data-language="go">func Getpagesize() int</pre> <p>Getpagesize returns the underlying system's memory page size. </p>
+<h2 id="Getpid">func <span>Getpid</span> </h2> <pre data-language="go">func Getpid() int</pre> <p>Getpid returns the process id of the caller. </p>
+<h2 id="Getppid">func <span>Getppid</span> </h2> <pre data-language="go">func Getppid() int</pre> <p>Getppid returns the process id of the caller's parent. </p>
+<h2 id="Getuid">func <span>Getuid</span> </h2> <pre data-language="go">func Getuid() int</pre> <p>Getuid returns the numeric user id of the caller. </p>
+<p>On Windows, it returns -1. </p>
+<h2 id="Getwd">func <span>Getwd</span> </h2> <pre data-language="go">func Getwd() (dir string, err error)</pre> <p>Getwd returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), Getwd may return any one of them. </p>
+<h2 id="Hostname">func <span>Hostname</span> </h2> <pre data-language="go">func Hostname() (name string, err error)</pre> <p>Hostname returns the host name reported by the kernel. </p>
+<h2 id="IsExist">func <span>IsExist</span> </h2> <pre data-language="go">func IsExist(err error) bool</pre> <p>IsExist returns a boolean indicating whether the error is known to report that a file or directory already exists. It is satisfied by ErrExist as well as some syscall errors. </p>
+<p>This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrExist). </p>
+<h2 id="IsNotExist">func <span>IsNotExist</span> </h2> <pre data-language="go">func IsNotExist(err error) bool</pre> <p>IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist. It is satisfied by ErrNotExist as well as some syscall errors. </p>
+<p>This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrNotExist). </p>
+<h2 id="IsPathSeparator">func <span>IsPathSeparator</span> </h2> <pre data-language="go">func IsPathSeparator(c uint8) bool</pre> <p>IsPathSeparator reports whether c is a directory separator character. </p>
+<h2 id="IsPermission">func <span>IsPermission</span> </h2> <pre data-language="go">func IsPermission(err error) bool</pre> <p>IsPermission returns a boolean indicating whether the error is known to report that permission is denied. It is satisfied by ErrPermission as well as some syscall errors. </p>
+<p>This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrPermission). </p>
+<h2 id="IsTimeout">func <span>IsTimeout</span> <span title="Added in Go 1.10">1.10</span> </h2> <pre data-language="go">func IsTimeout(err error) bool</pre> <p>IsTimeout returns a boolean indicating whether the error is known to report that a timeout occurred. </p>
+<p>This function predates errors.Is, and the notion of whether an error indicates a timeout can be ambiguous. For example, the Unix error EWOULDBLOCK sometimes indicates a timeout and sometimes does not. New code should use errors.Is with a value appropriate to the call returning the error, such as os.ErrDeadlineExceeded. </p>
+<h2 id="Lchown">func <span>Lchown</span> </h2> <pre data-language="go">func Lchown(name string, uid, gid int) error</pre> <p>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. </p>
+<p>On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError. </p>
+<h2 id="Link">func <span>Link</span> </h2> <pre data-language="go">func Link(oldname, newname string) error</pre> <p>Link creates newname as a hard link to the oldname file. If there is an error, it will be of type *LinkError. </p>
+<h2 id="LookupEnv">func <span>LookupEnv</span> <span title="Added in Go 1.5">1.5</span> </h2> <pre data-language="go">func LookupEnv(key string) (string, bool)</pre> <p>LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false. </p> <h4 id="example_LookupEnv"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">show := func(key string) {
+ val, ok := os.LookupEnv(key)
+ if !ok {
+ fmt.Printf("%s not set\n", key)
+ } else {
+ fmt.Printf("%s=%s\n", key, val)
+ }
+}
+
+os.Setenv("SOME_KEY", "value")
+os.Setenv("EMPTY_KEY", "")
+
+show("SOME_KEY")
+show("EMPTY_KEY")
+show("MISSING_KEY")
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">SOME_KEY=value
+EMPTY_KEY=
+MISSING_KEY not set
+</pre> <h2 id="Mkdir">func <span>Mkdir</span> </h2> <pre data-language="go">func Mkdir(name string, perm FileMode) error</pre> <p>Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError. </p> <h4 id="example_Mkdir"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+err := os.Mkdir("testdir", 0750)
+if err != nil &amp;&amp; !os.IsExist(err) {
+ log.Fatal(err)
+}
+err = os.WriteFile("testdir/testfile.txt", []byte("Hello, Gophers!"), 0660)
+if err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="MkdirAll">func <span>MkdirAll</span> </h2> <pre data-language="go">func MkdirAll(path string, perm FileMode) error</pre> <p>MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil. </p> <h4 id="example_MkdirAll"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+err := os.MkdirAll("test/subdir", 0750)
+if err != nil {
+ log.Fatal(err)
+}
+err = os.WriteFile("test/subdir/testfile.txt", []byte("Hello, Gophers!"), 0660)
+if err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="MkdirTemp">func <span>MkdirTemp</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func MkdirTemp(dir, pattern string) (string, error)</pre> <p>MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory's name is generated by adding a random string to the end of pattern. If pattern includes a "*", the random string replaces the last "*" instead. If dir is the empty string, MkdirTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when it is no longer needed. </p> <h4 id="example_MkdirTemp"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+dir, err := os.MkdirTemp("", "example")
+if err != nil {
+ log.Fatal(err)
+}
+defer os.RemoveAll(dir) // clean up
+
+file := filepath.Join(dir, "tmpfile")
+if err := os.WriteFile(file, []byte("content"), 0666); err != nil {
+ log.Fatal(err)
+}
+</pre> <h4 id="example_MkdirTemp_suffix"> <span class="text">Example (Suffix)</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+logsDir, err := os.MkdirTemp("", "*-logs")
+if err != nil {
+ log.Fatal(err)
+}
+defer os.RemoveAll(logsDir) // clean up
+
+// Logs can be cleaned out earlier if needed by searching
+// for all directories whose suffix ends in *-logs.
+globPattern := filepath.Join(os.TempDir(), "*-logs")
+matches, err := filepath.Glob(globPattern)
+if err != nil {
+ log.Fatalf("Failed to match %q: %v", globPattern, err)
+}
+
+for _, match := range matches {
+ if err := os.RemoveAll(match); err != nil {
+ log.Printf("Failed to remove %q: %v", match, err)
+ }
+}
+</pre> <h2 id="NewSyscallError">func <span>NewSyscallError</span> </h2> <pre data-language="go">func NewSyscallError(syscall string, err error) error</pre> <p>NewSyscallError returns, as an error, a new SyscallError with the given system call name and error details. As a convenience, if err is nil, NewSyscallError returns nil. </p>
+<h2 id="Pipe">func <span>Pipe</span> </h2> <pre data-language="go">func Pipe() (r *File, w *File, err error)</pre> <p>Pipe returns a connected pair of Files; reads from r return bytes written to w. It returns the files and an error, if any. </p>
+<h2 id="ReadFile">func <span>ReadFile</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func ReadFile(name string) ([]byte, error)</pre> <p>ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported. </p> <h4 id="example_ReadFile"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">data, err := os.ReadFile("testdata/hello")
+if err != nil {
+ log.Fatal(err)
+}
+os.Stdout.Write(data)
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">Hello, Gophers!
+</pre> <h2 id="Readlink">func <span>Readlink</span> </h2> <pre data-language="go">func Readlink(name string) (string, error)</pre> <p>Readlink returns the destination of the named symbolic link. If there is an error, it will be of type *PathError. </p>
+<p>If the link destination is relative, Readlink returns the relative path without resolving it to an absolute one. </p> <h4 id="example_Readlink"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">// First, we create a relative symlink to a file.
+d, err := os.MkdirTemp("", "")
+if err != nil {
+ log.Fatal(err)
+}
+defer os.RemoveAll(d)
+targetPath := filepath.Join(d, "hello.txt")
+if err := os.WriteFile(targetPath, []byte("Hello, Gophers!"), 0644); err != nil {
+ log.Fatal(err)
+}
+linkPath := filepath.Join(d, "hello.link")
+if err := os.Symlink("hello.txt", filepath.Join(d, "hello.link")); err != nil {
+ if errors.Is(err, errors.ErrUnsupported) {
+ // Allow the example to run on platforms that do not support symbolic links.
+ fmt.Printf("%s links to %s\n", filepath.Base(linkPath), "hello.txt")
+ return
+ }
+ log.Fatal(err)
+}
+
+// Readlink returns the relative path as passed to os.Symlink.
+dst, err := os.Readlink(linkPath)
+if err != nil {
+ log.Fatal(err)
+}
+fmt.Printf("%s links to %s\n", filepath.Base(linkPath), dst)
+
+var dstAbs string
+if filepath.IsAbs(dst) {
+ dstAbs = dst
+} else {
+ // Symlink targets are relative to the directory containing the link.
+ dstAbs = filepath.Join(filepath.Dir(linkPath), dst)
+}
+
+// Check that the target is correct by comparing it with os.Stat
+// on the original target path.
+dstInfo, err := os.Stat(dstAbs)
+if err != nil {
+ log.Fatal(err)
+}
+targetInfo, err := os.Stat(targetPath)
+if err != nil {
+ log.Fatal(err)
+}
+if !os.SameFile(dstInfo, targetInfo) {
+ log.Fatalf("link destination (%s) is not the same file as %s", dstAbs, targetPath)
+}
+
+</pre> <p>Output:</p> <pre class="output" data-language="go">hello.link links to hello.txt
+</pre> <h2 id="Remove">func <span>Remove</span> </h2> <pre data-language="go">func Remove(name string) error</pre> <p>Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError. </p>
+<h2 id="RemoveAll">func <span>RemoveAll</span> </h2> <pre data-language="go">func RemoveAll(path string) error</pre> <p>RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError. </p>
+<h2 id="Rename">func <span>Rename</span> </h2> <pre data-language="go">func Rename(oldpath, newpath string) error</pre> <p>Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. Even within the same directory, on non-Unix platforms Rename is not an atomic operation. If there is an error, it will be of type *LinkError. </p>
+<h2 id="SameFile">func <span>SameFile</span> </h2> <pre data-language="go">func SameFile(fi1, fi2 FileInfo) bool</pre> <p>SameFile reports whether fi1 and fi2 describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by this package's Stat. It returns false in other cases. </p>
+<h2 id="Setenv">func <span>Setenv</span> </h2> <pre data-language="go">func Setenv(key, value string) error</pre> <p>Setenv sets the value of the environment variable named by the key. It returns an error, if any. </p>
+<h2 id="Symlink">func <span>Symlink</span> </h2> <pre data-language="go">func Symlink(oldname, newname string) error</pre> <p>Symlink creates newname as a symbolic link to oldname. On Windows, a symlink to a non-existent oldname creates a file symlink; if oldname is later created as a directory the symlink will not work. If there is an error, it will be of type *LinkError. </p>
+<h2 id="TempDir">func <span>TempDir</span> </h2> <pre data-language="go">func TempDir() string</pre> <p>TempDir returns the default directory to use for temporary files. </p>
+<p>On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp. </p>
+<p>The directory is neither guaranteed to exist nor have accessible permissions. </p>
+<h2 id="Truncate">func <span>Truncate</span> </h2> <pre data-language="go">func Truncate(name string, size int64) error</pre> <p>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. </p>
+<h2 id="Unsetenv">func <span>Unsetenv</span> <span title="Added in Go 1.4">1.4</span> </h2> <pre data-language="go">func Unsetenv(key string) error</pre> <p>Unsetenv unsets a single environment variable. </p> <h4 id="example_Unsetenv"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+os.Setenv("TMPDIR", "/my/tmp")
+defer os.Unsetenv("TMPDIR")
+</pre> <h2 id="UserCacheDir">func <span>UserCacheDir</span> <span title="Added in Go 1.11">1.11</span> </h2> <pre data-language="go">func UserCacheDir() (string, error)</pre> <p>UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own application-specific subdirectory within this one and use that. </p>
+<p>On Unix systems, it returns $XDG_CACHE_HOME as specified by <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html</a> if non-empty, else $HOME/.cache. On Darwin, it returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache. </p>
+<p>If the location cannot be determined (for example, $HOME is not defined), then it will return an error. </p> <h4 id="example_UserCacheDir"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">dir, dirErr := os.UserCacheDir()
+if dirErr == nil {
+ dir = filepath.Join(dir, "ExampleUserCacheDir")
+}
+
+getCache := func(name string) ([]byte, error) {
+ if dirErr != nil {
+ return nil, &amp;os.PathError{Op: "getCache", Path: name, Err: os.ErrNotExist}
+ }
+ return os.ReadFile(filepath.Join(dir, name))
+}
+
+var mkdirOnce sync.Once
+putCache := func(name string, b []byte) error {
+ if dirErr != nil {
+ return &amp;os.PathError{Op: "putCache", Path: name, Err: dirErr}
+ }
+ mkdirOnce.Do(func() {
+ if err := os.MkdirAll(dir, 0700); err != nil {
+ log.Printf("can't create user cache dir: %v", err)
+ }
+ })
+ return os.WriteFile(filepath.Join(dir, name), b, 0600)
+}
+
+// Read and store cached data.
+// …
+_ = getCache
+_ = putCache
+
+</pre> <h2 id="UserConfigDir">func <span>UserConfigDir</span> <span title="Added in Go 1.13">1.13</span> </h2> <pre data-language="go">func UserConfigDir() (string, error)</pre> <p>UserConfigDir returns the default root directory to use for user-specific configuration data. Users should create their own application-specific subdirectory within this one and use that. </p>
+<p>On Unix systems, it returns $XDG_CONFIG_HOME as specified by <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html</a> if non-empty, else $HOME/.config. On Darwin, it returns $HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib. </p>
+<p>If the location cannot be determined (for example, $HOME is not defined), then it will return an error. </p> <h4 id="example_UserConfigDir"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">dir, dirErr := os.UserConfigDir()
+
+var (
+ configPath string
+ origConfig []byte
+)
+if dirErr == nil {
+ configPath = filepath.Join(dir, "ExampleUserConfigDir", "example.conf")
+ var err error
+ origConfig, err = os.ReadFile(configPath)
+ if err != nil &amp;&amp; !os.IsNotExist(err) {
+ // The user has a config file but we couldn't read it.
+ // Report the error instead of ignoring their configuration.
+ log.Fatal(err)
+ }
+}
+
+// Use and perhaps make changes to the config.
+config := bytes.Clone(origConfig)
+// …
+
+// Save changes.
+if !bytes.Equal(config, origConfig) {
+ if configPath == "" {
+ log.Printf("not saving config changes: %v", dirErr)
+ } else {
+ err := os.MkdirAll(filepath.Dir(configPath), 0700)
+ if err == nil {
+ err = os.WriteFile(configPath, config, 0600)
+ }
+ if err != nil {
+ log.Printf("error saving config changes: %v", err)
+ }
+ }
+}
+
+</pre> <h2 id="UserHomeDir">func <span>UserHomeDir</span> <span title="Added in Go 1.12">1.12</span> </h2> <pre data-language="go">func UserHomeDir() (string, error)</pre> <p>UserHomeDir returns the current user's home directory. </p>
+<p>On Unix, including macOS, it returns the $HOME environment variable. On Windows, it returns %USERPROFILE%. On Plan 9, it returns the $home environment variable. </p>
+<p>If the expected variable is not set in the environment, UserHomeDir returns either a platform-specific default value or a non-nil error. </p>
+<h2 id="WriteFile">func <span>WriteFile</span> <span title="Added in Go 1.16">1.16</span> </h2> <pre data-language="go">func WriteFile(name string, data []byte, perm FileMode) error</pre> <p>WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions. Since WriteFile requires multiple system calls to complete, a failure mid-operation can leave the file in a partially written state. </p> <h4 id="example_WriteFile"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+err := os.WriteFile("testdata/hello", []byte("Hello, Gophers!"), 0666)
+if err != nil {
+ log.Fatal(err)
+}
+</pre> <h2 id="DirEntry">type <span>DirEntry</span> <span title="Added in Go 1.16">1.16</span> </h2> <p>A DirEntry is an entry read from a directory (using the ReadDir function or a File's ReadDir method). </p>
+<pre data-language="go">type DirEntry = fs.DirEntry</pre> <h3 id="ReadDir">func <span>ReadDir</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func ReadDir(name string) ([]DirEntry, error)</pre> <p>ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error. </p> <h4 id="example_ReadDir"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+files, err := os.ReadDir(".")
+if err != nil {
+ log.Fatal(err)
+}
+
+for _, file := range files {
+ fmt.Println(file.Name())
+}
+</pre> <h2 id="File">type <span>File</span> </h2> <p>File represents an open file descriptor. </p>
+<pre data-language="go">type File struct {
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="Create">func <span>Create</span> </h3> <pre data-language="go">func Create(name string) (*File, error)</pre> <p>Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError. </p>
+<h3 id="CreateTemp">func <span>CreateTemp</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func CreateTemp(dir, pattern string) (*File, error)</pre> <p>CreateTemp creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting file. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, CreateTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling CreateTemp simultaneously will not choose the same file. The caller can use the file's Name method to find the pathname of the file. It is the caller's responsibility to remove the file when it is no longer needed. </p> <h4 id="example_CreateTemp"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+f, err := os.CreateTemp("", "example")
+if err != nil {
+ log.Fatal(err)
+}
+defer os.Remove(f.Name()) // clean up
+
+if _, err := f.Write([]byte("content")); err != nil {
+ log.Fatal(err)
+}
+if err := f.Close(); err != nil {
+ log.Fatal(err)
+}
+</pre> <h4 id="example_CreateTemp_suffix"> <span class="text">Example (Suffix)</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+f, err := os.CreateTemp("", "example.*.txt")
+if err != nil {
+ log.Fatal(err)
+}
+defer os.Remove(f.Name()) // clean up
+
+if _, err := f.Write([]byte("content")); err != nil {
+ f.Close()
+ log.Fatal(err)
+}
+if err := f.Close(); err != nil {
+ log.Fatal(err)
+}
+</pre> <h3 id="NewFile">func <span>NewFile</span> </h3> <pre data-language="go">func NewFile(fd uintptr, name string) *File</pre> <p>NewFile returns a new File with the given file descriptor and name. The returned value will be nil if fd is not a valid file descriptor. On Unix systems, if the file descriptor is in non-blocking mode, NewFile will attempt to return a pollable File (one for which the SetDeadline methods work). </p>
+<p>After passing it to NewFile, fd may become invalid under the same conditions described in the comments of the Fd method, and the same constraints apply. </p>
+<h3 id="Open">func <span>Open</span> </h3> <pre data-language="go">func Open(name string) (*File, error)</pre> <p>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. If there is an error, it will be of type *PathError. </p>
+<h3 id="OpenFile">func <span>OpenFile</span> </h3> <pre data-language="go">func OpenFile(name string, flag int, perm FileMode) (*File, error)</pre> <p>OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask). If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError. </p> <h4 id="example_OpenFile"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+f, err := os.OpenFile("notes.txt", os.O_RDWR|os.O_CREATE, 0644)
+if err != nil {
+ log.Fatal(err)
+}
+if err := f.Close(); err != nil {
+ log.Fatal(err)
+}
+</pre> <h4 id="example_OpenFile_append"> <span class="text">Example (Append)</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+// If the file doesn't exist, create it, or append to the file
+f, err := os.OpenFile("access.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+if err != nil {
+ log.Fatal(err)
+}
+if _, err := f.Write([]byte("appended some data\n")); err != nil {
+ f.Close() // ignore error; Write error takes precedence
+ log.Fatal(err)
+}
+if err := f.Close(); err != nil {
+ log.Fatal(err)
+}
+</pre> <h3 id="File.Chdir">func (*File) <span>Chdir</span> </h3> <pre data-language="go">func (f *File) Chdir() error</pre> <p>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. </p>
+<h3 id="File.Chmod">func (*File) <span>Chmod</span> </h3> <pre data-language="go">func (f *File) Chmod(mode FileMode) error</pre> <p>Chmod changes the mode of the file to mode. If there is an error, it will be of type *PathError. </p>
+<h3 id="File.Chown">func (*File) <span>Chown</span> </h3> <pre data-language="go">func (f *File) Chown(uid, gid int) error</pre> <p>Chown changes the numeric uid and gid of the named file. If there is an error, it will be of type *PathError. </p>
+<p>On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError. </p>
+<h3 id="File.Close">func (*File) <span>Close</span> </h3> <pre data-language="go">func (f *File) Close() error</pre> <p>Close closes the File, rendering it unusable for I/O. On files that support SetDeadline, any pending I/O operations will be canceled and return immediately with an ErrClosed error. Close will return an error if it has already been called. </p>
+<h3 id="File.Fd">func (*File) <span>Fd</span> </h3> <pre data-language="go">func (f *File) Fd() uintptr</pre> <p>Fd returns the integer Unix file descriptor referencing the open file. If f is closed, the file descriptor becomes invalid. If f is garbage collected, a finalizer may close the file descriptor, making it invalid; see runtime.SetFinalizer for more information on when a finalizer might be run. On Unix systems this will cause the SetDeadline methods to stop working. Because file descriptors can be reused, the returned file descriptor may only be closed through the Close method of f, or by its finalizer during garbage collection. Otherwise, during garbage collection the finalizer may close an unrelated file descriptor with the same (reused) number. </p>
+<p>As an alternative, see the f.SyscallConn method. </p>
+<h3 id="File.Name">func (*File) <span>Name</span> </h3> <pre data-language="go">func (f *File) Name() string</pre> <p>Name returns the name of the file as presented to Open. </p>
+<h3 id="File.Read">func (*File) <span>Read</span> </h3> <pre data-language="go">func (f *File) Read(b []byte) (n int, err error)</pre> <p>Read reads up to len(b) bytes from the File and stores them in b. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF. </p>
+<h3 id="File.ReadAt">func (*File) <span>ReadAt</span> </h3> <pre data-language="go">func (f *File) ReadAt(b []byte, off int64) (n int, err error)</pre> <p>ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n &lt; len(b). At end of file, that error is io.EOF. </p>
+<h3 id="File.ReadDir">func (*File) <span>ReadDir</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (f *File) ReadDir(n int) ([]DirEntry, error)</pre> <p>ReadDir reads the contents of the directory associated with the file f and returns a slice of DirEntry values in directory order. Subsequent calls on the same file will yield later DirEntry records in the directory. </p>
+<p>If n &gt; 0, ReadDir returns at most n DirEntry records. In this case, if ReadDir returns an empty slice, it will return an error explaining why. At the end of a directory, the error is io.EOF. </p>
+<p>If n &lt;= 0, ReadDir returns all the DirEntry records remaining in the directory. When it succeeds, it returns a nil error (not io.EOF). </p>
+<h3 id="File.ReadFrom">func (*File) <span>ReadFrom</span> <span title="Added in Go 1.15">1.15</span> </h3> <pre data-language="go">func (f *File) ReadFrom(r io.Reader) (n int64, err error)</pre> <p>ReadFrom implements io.ReaderFrom. </p>
+<h3 id="File.Readdir">func (*File) <span>Readdir</span> </h3> <pre data-language="go">func (f *File) Readdir(n int) ([]FileInfo, error)</pre> <p>Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos. </p>
+<p>If n &gt; 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF. </p>
+<p>If n &lt;= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error. </p>
+<p>Most clients are better served by the more efficient ReadDir method. </p>
+<h3 id="File.Readdirnames">func (*File) <span>Readdirnames</span> </h3> <pre data-language="go">func (f *File) Readdirnames(n int) (names []string, err error)</pre> <p>Readdirnames reads the contents of the directory associated with file and returns a slice of up to n names of files in the directory, in directory order. Subsequent calls on the same file will yield further names. </p>
+<p>If n &gt; 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF. </p>
+<p>If n &lt;= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error. </p>
+<h3 id="File.Seek">func (*File) <span>Seek</span> </h3> <pre data-language="go">func (f *File) Seek(offset int64, whence int) (ret int64, err error)</pre> <p>Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with O_APPEND is not specified. </p>
+<h3 id="File.SetDeadline">func (*File) <span>SetDeadline</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (f *File) SetDeadline(t time.Time) error</pre> <p>SetDeadline sets the read and write deadlines for a File. It is equivalent to calling both SetReadDeadline and SetWriteDeadline. </p>
+<p>Only some kinds of files support setting a deadline. Calls to SetDeadline for files that do not support deadlines will return ErrNoDeadline. On most systems ordinary files do not support deadlines, but pipes do. </p>
+<p>A deadline is an absolute time after which I/O operations fail with an error instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future. </p>
+<p>If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). That error implements the Timeout method, and calling the Timeout method will return true, but there are other possible errors for which the Timeout will return true even if the deadline has not been exceeded. </p>
+<p>An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls. </p>
+<p>A zero value for t means I/O operations will not time out. </p>
+<h3 id="File.SetReadDeadline">func (*File) <span>SetReadDeadline</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (f *File) SetReadDeadline(t time.Time) error</pre> <p>SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out. Not all files support setting deadlines; see SetDeadline. </p>
+<h3 id="File.SetWriteDeadline">func (*File) <span>SetWriteDeadline</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (f *File) SetWriteDeadline(t time.Time) error</pre> <p>SetWriteDeadline sets the deadline for any future Write calls and any currently-blocked Write call. Even if Write times out, it may return n &gt; 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out. Not all files support setting deadlines; see SetDeadline. </p>
+<h3 id="File.Stat">func (*File) <span>Stat</span> </h3> <pre data-language="go">func (f *File) Stat() (FileInfo, error)</pre> <p>Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError. </p>
+<h3 id="File.Sync">func (*File) <span>Sync</span> </h3> <pre data-language="go">func (f *File) Sync() error</pre> <p>Sync commits the current contents of the file to stable storage. Typically, this means flushing the file system's in-memory copy of recently written data to disk. </p>
+<h3 id="File.SyscallConn">func (*File) <span>SyscallConn</span> <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (f *File) SyscallConn() (syscall.RawConn, error)</pre> <p>SyscallConn returns a raw file. This implements the syscall.Conn interface. </p>
+<h3 id="File.Truncate">func (*File) <span>Truncate</span> </h3> <pre data-language="go">func (f *File) Truncate(size int64) error</pre> <p>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. </p>
+<h3 id="File.Write">func (*File) <span>Write</span> </h3> <pre data-language="go">func (f *File) Write(b []byte) (n int, err error)</pre> <p>Write writes len(b) bytes from b to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b). </p>
+<h3 id="File.WriteAt">func (*File) <span>WriteAt</span> </h3> <pre data-language="go">func (f *File) WriteAt(b []byte, off int64) (n int, err error)</pre> <p>WriteAt writes len(b) bytes to the File starting at byte offset off. It returns the number of bytes written and an error, if any. WriteAt returns a non-nil error when n != len(b). </p>
+<p>If file was opened with the O_APPEND flag, WriteAt returns an error. </p>
+<h3 id="File.WriteString">func (*File) <span>WriteString</span> </h3> <pre data-language="go">func (f *File) WriteString(s string) (n int, err error)</pre> <p>WriteString is like Write, but writes the contents of string s rather than a slice of bytes. </p>
+<h3 id="File.WriteTo">func (*File) <span>WriteTo</span> <span title="Added in Go 1.22">1.22</span> </h3> <pre data-language="go">func (f *File) WriteTo(w io.Writer) (n int64, err error)</pre> <p>WriteTo implements io.WriterTo. </p>
+<h2 id="FileInfo">type <span>FileInfo</span> </h2> <p>A FileInfo describes a file and is returned by Stat and Lstat. </p>
+<pre data-language="go">type FileInfo = fs.FileInfo</pre> <h3 id="Lstat">func <span>Lstat</span> </h3> <pre data-language="go">func Lstat(name string) (FileInfo, error)</pre> <p>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. </p>
+<p>On Windows, if the file is a reparse point that is a surrogate for another named entity (such as a symbolic link or mounted folder), the returned FileInfo describes the reparse point, and makes no attempt to resolve it. </p>
+<h3 id="Stat">func <span>Stat</span> </h3> <pre data-language="go">func Stat(name string) (FileInfo, error)</pre> <p>Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError. </p>
+<h2 id="FileMode">type <span>FileMode</span> </h2> <p>A FileMode represents a file's mode and permission bits. The bits have the same definition on all systems, so that information about files can be moved from one system to another portably. Not all bits apply to all systems. The only required bit is ModeDir for directories. </p>
+<pre data-language="go">type FileMode = fs.FileMode</pre> <h4 id="example_FileMode"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+fi, err := os.Lstat("some-filename")
+if err != nil {
+ log.Fatal(err)
+}
+
+fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0400, 0777, etc.
+switch mode := fi.Mode(); {
+case mode.IsRegular():
+ fmt.Println("regular file")
+case mode.IsDir():
+ fmt.Println("directory")
+case mode&amp;fs.ModeSymlink != 0:
+ fmt.Println("symbolic link")
+case mode&amp;fs.ModeNamedPipe != 0:
+ fmt.Println("named pipe")
+}
+</pre> <h2 id="LinkError">type <span>LinkError</span> </h2> <p>LinkError records an error during a link or symlink or rename system call and the paths that caused it. </p>
+<pre data-language="go">type LinkError struct {
+ Op string
+ Old string
+ New string
+ Err error
+}
+</pre> <h3 id="LinkError.Error">func (*LinkError) <span>Error</span> </h3> <pre data-language="go">func (e *LinkError) Error() string</pre> <h3 id="LinkError.Unwrap">func (*LinkError) <span>Unwrap</span> <span title="Added in Go 1.13">1.13</span> </h3> <pre data-language="go">func (e *LinkError) Unwrap() error</pre> <h2 id="PathError">type <span>PathError</span> </h2> <p>PathError records an error and the operation and file path that caused it. </p>
+<pre data-language="go">type PathError = fs.PathError</pre> <h2 id="ProcAttr">type <span>ProcAttr</span> </h2> <p>ProcAttr holds the attributes that will be applied to a new process started by StartProcess. </p>
+<pre data-language="go">type ProcAttr struct {
+ // If Dir is non-empty, the child changes into the directory before
+ // creating the process.
+ Dir string
+ // If Env is non-nil, it gives the environment variables for the
+ // new process in the form returned by Environ.
+ // If it is nil, the result of Environ will be used.
+ Env []string
+ // Files specifies the open files inherited by the new process. The
+ // first three entries correspond to standard input, standard output, and
+ // standard error. An implementation may support additional entries,
+ // depending on the underlying operating system. A nil entry corresponds
+ // to that file being closed when the process starts.
+ // On Unix systems, StartProcess will change these File values
+ // to blocking mode, which means that SetDeadline will stop working
+ // and calling Close will not interrupt a Read or Write.
+ Files []*File
+
+ // Operating system-specific process creation attributes.
+ // Note that setting this field means that your program
+ // may not execute properly or even compile on some
+ // operating systems.
+ Sys *syscall.SysProcAttr
+}
+</pre> <h2 id="Process">type <span>Process</span> </h2> <p>Process stores the information about a process created by StartProcess. </p>
+<pre data-language="go">type Process struct {
+ Pid int
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="FindProcess">func <span>FindProcess</span> </h3> <pre data-language="go">func FindProcess(pid int) (*Process, error)</pre> <p>FindProcess looks for a running process by its pid. </p>
+<p>The Process it returns can be used to obtain information about the underlying operating system process. </p>
+<p>On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists. To test whether the process actually exists, see whether p.Signal(syscall.Signal(0)) reports an error. </p>
+<h3 id="StartProcess">func <span>StartProcess</span> </h3> <pre data-language="go">func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)</pre> <p>StartProcess starts a new process with the program, arguments and attributes specified by name, argv and attr. The argv slice will become os.Args in the new process, so it normally starts with the program name. </p>
+<p>If the calling goroutine has locked the operating system thread with runtime.LockOSThread and modified any inheritable OS-level thread state (for example, Linux or Plan 9 name spaces), the new process will inherit the caller's thread state. </p>
+<p>StartProcess is a low-level interface. The os/exec package provides higher-level interfaces. </p>
+<p>If there is an error, it will be of type *PathError. </p>
+<h3 id="Process.Kill">func (*Process) <span>Kill</span> </h3> <pre data-language="go">func (p *Process) Kill() error</pre> <p>Kill causes the Process to exit immediately. Kill does not wait until the Process has actually exited. This only kills the Process itself, not any other processes it may have started. </p>
+<h3 id="Process.Release">func (*Process) <span>Release</span> </h3> <pre data-language="go">func (p *Process) Release() error</pre> <p>Release releases any resources associated with the Process p, rendering it unusable in the future. Release only needs to be called if Wait is not. </p>
+<h3 id="Process.Signal">func (*Process) <span>Signal</span> </h3> <pre data-language="go">func (p *Process) Signal(sig Signal) error</pre> <p>Signal sends a signal to the Process. Sending Interrupt on Windows is not implemented. </p>
+<h3 id="Process.Wait">func (*Process) <span>Wait</span> </h3> <pre data-language="go">func (p *Process) Wait() (*ProcessState, error)</pre> <p>Wait waits for the Process to exit, and then returns a ProcessState describing its status and an error, if any. Wait releases any resources associated with the Process. On most operating systems, the Process must be a child of the current process or an error will be returned. </p>
+<h2 id="ProcessState">type <span>ProcessState</span> </h2> <p>ProcessState stores information about a process, as reported by Wait. </p>
+<pre data-language="go">type ProcessState struct {
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="ProcessState.ExitCode">func (*ProcessState) <span>ExitCode</span> <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (p *ProcessState) ExitCode() int</pre> <p>ExitCode returns the exit code of the exited process, or -1 if the process hasn't exited or was terminated by a signal. </p>
+<h3 id="ProcessState.Exited">func (*ProcessState) <span>Exited</span> </h3> <pre data-language="go">func (p *ProcessState) Exited() bool</pre> <p>Exited reports whether the program has exited. On Unix systems this reports true if the program exited due to calling exit, but false if the program terminated due to a signal. </p>
+<h3 id="ProcessState.Pid">func (*ProcessState) <span>Pid</span> </h3> <pre data-language="go">func (p *ProcessState) Pid() int</pre> <p>Pid returns the process id of the exited process. </p>
+<h3 id="ProcessState.String">func (*ProcessState) <span>String</span> </h3> <pre data-language="go">func (p *ProcessState) String() string</pre> <h3 id="ProcessState.Success">func (*ProcessState) <span>Success</span> </h3> <pre data-language="go">func (p *ProcessState) Success() bool</pre> <p>Success reports whether the program exited successfully, such as with exit status 0 on Unix. </p>
+<h3 id="ProcessState.Sys">func (*ProcessState) <span>Sys</span> </h3> <pre data-language="go">func (p *ProcessState) Sys() any</pre> <p>Sys returns system-dependent exit information about the process. Convert it to the appropriate underlying type, such as syscall.WaitStatus on Unix, to access its contents. </p>
+<h3 id="ProcessState.SysUsage">func (*ProcessState) <span>SysUsage</span> </h3> <pre data-language="go">func (p *ProcessState) SysUsage() any</pre> <p>SysUsage returns system-dependent resource usage information about the exited process. Convert it to the appropriate underlying type, such as *syscall.Rusage on Unix, to access its contents. (On Unix, *syscall.Rusage matches struct rusage as defined in the getrusage(2) manual page.) </p>
+<h3 id="ProcessState.SystemTime">func (*ProcessState) <span>SystemTime</span> </h3> <pre data-language="go">func (p *ProcessState) SystemTime() time.Duration</pre> <p>SystemTime returns the system CPU time of the exited process and its children. </p>
+<h3 id="ProcessState.UserTime">func (*ProcessState) <span>UserTime</span> </h3> <pre data-language="go">func (p *ProcessState) UserTime() time.Duration</pre> <p>UserTime returns the user CPU time of the exited process and its children. </p>
+<h2 id="Signal">type <span>Signal</span> </h2> <p>A Signal represents an operating system signal. The usual underlying implementation is operating system-dependent: on Unix it is syscall.Signal. </p>
+<pre data-language="go">type Signal interface {
+ String() string
+ Signal() // to distinguish from other Stringers
+}</pre> <p>The only signal values guaranteed to be present in the os package on all systems are os.Interrupt (send the process an interrupt) and os.Kill (force the process to exit). On Windows, sending os.Interrupt to a process with os.Process.Signal is not implemented; it will return an error instead of sending a signal. </p>
+<pre data-language="go">var (
+ Interrupt Signal = syscall.SIGINT
+ Kill Signal = syscall.SIGKILL
+)</pre> <h2 id="SyscallError">type <span>SyscallError</span> </h2> <p>SyscallError records an error from a specific system call. </p>
+<pre data-language="go">type SyscallError struct {
+ Syscall string
+ Err error
+}
+</pre> <h3 id="SyscallError.Error">func (*SyscallError) <span>Error</span> </h3> <pre data-language="go">func (e *SyscallError) Error() string</pre> <h3 id="SyscallError.Timeout">func (*SyscallError) <span>Timeout</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (e *SyscallError) Timeout() bool</pre> <p>Timeout reports whether this error represents a timeout. </p>
+<h3 id="SyscallError.Unwrap">func (*SyscallError) <span>Unwrap</span> <span title="Added in Go 1.13">1.13</span> </h3> <pre data-language="go">func (e *SyscallError) Unwrap() error</pre> <h2 id="pkg-subdirectories">Subdirectories</h2> <div class="pkg-dir"> <table> <tr> <th class="pkg-name">Name</th> <th class="pkg-synopsis">Synopsis</th> </tr> <tr> <td colspan="2"><a href="../index">..</a></td> </tr> <tr> <td class="pkg-name"> <a href="exec/index">exec</a> </td> <td class="pkg-synopsis"> Package exec runs external commands. </td> </tr> <tr> <td class="pkg-name"> <a href="signal/index">signal</a> </td> <td class="pkg-synopsis"> Package signal implements access to incoming signals. </td> </tr> <tr> <td class="pkg-name"> <a href="user/index">user</a> </td> <td class="pkg-synopsis"> Package user allows user account lookups by name or id. </td> </tr> </table> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/os/" class="_attribution-link">http://golang.org/pkg/os/</a>
+ </p>
+</div>