diff options
Diffstat (limited to 'src/os/types.go')
-rw-r--r-- | src/os/types.go | 86 |
1 files changed, 18 insertions, 68 deletions
diff --git a/src/os/types.go b/src/os/types.go index 4b6c084838..d8edd98b68 100644 --- a/src/os/types.go +++ b/src/os/types.go @@ -5,8 +5,8 @@ package os import ( + "io/fs" "syscall" - "time" ) // Getpagesize returns the underlying system's memory page size. @@ -18,21 +18,14 @@ type File struct { } // A FileInfo describes a file and is returned by Stat and Lstat. -type FileInfo interface { - Name() string // base name of the file - Size() int64 // length in bytes for regular files; system-dependent for others - Mode() FileMode // file mode bits - ModTime() time.Time // modification time - IsDir() bool // abbreviation for Mode().IsDir() - Sys() interface{} // underlying data source (can return nil) -} +type FileInfo = fs.FileInfo // 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. -type FileMode uint32 +type FileMode = fs.FileMode // The defined file mode bits are the most significant bits of the FileMode. // The nine least-significant bits are the standard Unix rwxrwxrwx permissions. @@ -42,69 +35,26 @@ type FileMode uint32 const ( // The single letters are the abbreviations // used by the String method's formatting. - ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory - ModeAppend // a: append-only - ModeExclusive // l: exclusive use - ModeTemporary // T: temporary file; Plan 9 only - ModeSymlink // L: symbolic link - ModeDevice // D: device file - ModeNamedPipe // p: named pipe (FIFO) - ModeSocket // S: Unix domain socket - ModeSetuid // u: setuid - ModeSetgid // g: setgid - ModeCharDevice // c: Unix character device, when ModeDevice is set - ModeSticky // t: sticky - ModeIrregular // ?: non-regular file; nothing else is known about this file + 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 = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeCharDevice | ModeIrregular + ModeType = fs.ModeType - ModePerm FileMode = 0777 // Unix permission bits + ModePerm = fs.ModePerm // Unix permission bits, 0o777 ) -func (m FileMode) String() string { - const str = "dalTLDpSugct?" - var buf [32]byte // Mode is uint32. - w := 0 - for i, c := range str { - if m&(1<<uint(32-1-i)) != 0 { - buf[w] = byte(c) - w++ - } - } - if w == 0 { - buf[w] = '-' - w++ - } - const rwx = "rwxrwxrwx" - for i, c := range rwx { - if m&(1<<uint(9-1-i)) != 0 { - buf[w] = byte(c) - } else { - buf[w] = '-' - } - w++ - } - return string(buf[:w]) -} - -// IsDir reports whether m describes a directory. -// That is, it tests for the ModeDir bit being set in m. -func (m FileMode) IsDir() bool { - return m&ModeDir != 0 -} - -// IsRegular reports whether m describes a regular file. -// That is, it tests that no mode type bits are set. -func (m FileMode) IsRegular() bool { - return m&ModeType == 0 -} - -// Perm returns the Unix permission bits in m. -func (m FileMode) Perm() FileMode { - return m & ModePerm -} - func (fs *fileStat) Name() string { return fs.name } func (fs *fileStat) IsDir() bool { return fs.Mode().IsDir() } |