Documentation
¶
Overview ¶
Package os implements a subset of the Go "os" package. See https://godoc.org/os for details.
Note that the current implementation is blocking. This limitation should be removed in a future version.
Package os implements a subset of the Go "os" package. See https://godoc.org/os for details.
Note that the current implementation is blocking. This limitation should be removed in a future version.
Index ¶
- Constants
- Variables
- func Exit(code int)
- func Getenv(key string) string
- func Getpid() int
- func Getwd() (string, error)
- func Hostname() (name string, err error)
- func IsExist(err error) bool
- func IsNotExist(err error) bool
- func IsPathSeparator(c uint8) bool
- func IsPermission(err error) bool
- func LookupEnv(key string) (string, bool)
- func Mkdir(path string, perm FileMode) error
- func Mount(prefix string, filesystem Filesystem)
- func NewSyscallError(syscall string, err error) error
- func ReadFile(name string) ([]byte, error)
- func Readlink(name string) (string, error)
- func Remove(path string) error
- func TempDir() string
- func WriteFile(name string, data []byte, perm FileMode) error
- type DirEntry
- type File
- func (f *File) Close() (err error)
- func (f *File) Fd() uintptr
- func (f *File) Name() string
- func (f *File) Read(b []byte) (n int, err error)
- func (f *File) ReadAt(b []byte, off int64) (n int, err error)
- func (f *File) ReadDir(n int) ([]DirEntry, error)
- func (f *File) Readdir(n int) ([]FileInfo, error)
- func (f *File) Readdirnames(n int) (names []string, err error)
- func (f *File) Stat() (FileInfo, error)
- func (f *File) Sync() error
- func (f *File) SyscallConn() (syscall.RawConn, error)
- func (f *File) Write(b []byte) (n int, err error)
- type FileHandle
- type FileInfo
- type FileMode
- type Filesystem
- type PathError
- type Signal
- type SyscallError
Constants ¶
const ( PathSeparator = '/' // OS-specific path separator PathListSeparator = ':' // OS-specific path list separator )
Variables ¶
var ( ErrInvalid = errors.New("invalid argument") ErrPermission = errors.New("permission denied") ErrClosed = errors.New("file already closed") // Portable analogs of some common system call errors. // Note that these are exported for use in the Filesystem interface. ErrUnsupported = errors.New("operation not supported") ErrNotImplemented = errors.New("operation not implemented") ErrNotExist = errors.New("file not found") ErrExist = errors.New("file exists") )
var ( Stdin = &File{unixFileHandle(0), "/dev/stdin"} Stdout = &File{unixFileHandle(1), "/dev/stdout"} Stderr = &File{unixFileHandle(2), "/dev/stderr"} )
Stdin, Stdout, and Stderr are open Files pointing to the standard input, standard output, and standard error file descriptors.
var Args []string
Args hold the command-line arguments, starting with the program name.
Functions ¶
func Exit ¶ added in v0.7.0
func Exit(code int)
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.
func IsNotExist ¶ added in v0.7.0
func IsPathSeparator ¶ added in v0.7.0
IsPathSeparator reports whether c is a directory separator character.
func IsPermission ¶ added in v0.14.0
func Mkdir ¶ added in v0.7.0
Mkdir creates a directory. If the operation fails, it will return an error of type *PathError.
func Mount ¶ added in v0.14.0
func Mount(prefix string, filesystem Filesystem)
Mount mounts the given filesystem in the filesystem abstraction layer of the os package. It is not possible to unmount filesystems. Filesystems added later will override earlier filesystems.
The provided prefix must start and end with a forward slash. This is true for the root directory ("/") for example.
func NewSyscallError ¶ added in v0.14.0
func ReadFile ¶ added in v0.18.0
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.
func Readlink ¶ added in v0.7.0
Readlink is a stub (for now), always returning the string it was given
func Remove ¶ added in v0.14.0
Remove removes a file or (empty) directory. If the operation fails, it will return an error of type *PathError.
func TempDir ¶ added in v0.7.0
func TempDir() string
TempDir is a stub (for now), always returning the string "/tmp"
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents an open file descriptor.
func OpenFile ¶ added in v0.7.0
OpenFile opens the named file. If the operation fails, the returned error will be of type *PathError.
func (*File) Read ¶
Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
func (*File) Readdirnames ¶ added in v0.7.0
Readdirnames is a stub, not yet implemented
type FileHandle ¶ added in v0.14.0
type FileHandle interface { // Read reads up to len(b) bytes from the file. Read(b []byte) (n int, err error) // Write writes up to len(b) bytes to the file. Write(b []byte) (n int, err error) // Close closes the file, making it unusable for further writes. Close() (err error) }
FileHandle is an interface that should be implemented by filesystems implementing the Filesystem interface.
WARNING: this interface is not finalized and may change in a future version.
type Filesystem ¶ added in v0.14.0
type Filesystem interface { // OpenFile opens the named file. OpenFile(name string, flag int, perm FileMode) (FileHandle, error) // Mkdir creates a new directoy with the specified permission (before // umask). Some filesystems may not support directories or permissions. Mkdir(name string, perm FileMode) error // Remove removes the named file or (empty) directory. Remove(name string) error }
Filesystem provides an interface for generic filesystem drivers mounted in the os package. The errors returned must be one of the os.Err* errors, or a custom error if one doesn't exist. It should not be a *PathError because errors will be wrapped with a *PathError by the filesystem abstraction.
WARNING: this interface is not finalized and may change in a future version.
type PathError ¶ added in v0.7.0
PathError records an error and the operation and file path that caused it.
type Signal ¶ added in v0.14.0
type Signal interface { String() string Signal() // to distinguish from other Stringers }
type SyscallError ¶ added in v0.14.0
SyscallError records an error from a specific system call.
func (*SyscallError) Error ¶ added in v0.14.0
func (e *SyscallError) Error() string
func (*SyscallError) Unwrap ¶ added in v0.14.0
func (e *SyscallError) Unwrap() error