From 879b59292bb9e353db4119de2f9f4fe2f9a9f5b0 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 10 Feb 2009 16:40:06 -0800 Subject: drop the os_ prefix on the file names in os. os_test.go can stay. R=rsc DELTA=793 (392 added, 392 deleted, 9 changed) OCL=24777 CL=24804 --- src/lib/os/Makefile | 20 +++--- src/lib/os/env.go | 27 +++++++ src/lib/os/error.go | 100 ++++++++++++++++++++++++++ src/lib/os/file.go | 189 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/os/os_env.go | 27 ------- src/lib/os/os_error.go | 100 -------------------------- src/lib/os/os_file.go | 189 ------------------------------------------------- src/lib/os/os_time.go | 20 ------ src/lib/os/os_types.go | 60 ---------------- src/lib/os/time.go | 20 ++++++ src/lib/os/types.go | 60 ++++++++++++++++ 11 files changed, 406 insertions(+), 406 deletions(-) create mode 100644 src/lib/os/env.go create mode 100644 src/lib/os/error.go create mode 100644 src/lib/os/file.go delete mode 100644 src/lib/os/os_env.go delete mode 100644 src/lib/os/os_error.go delete mode 100644 src/lib/os/os_file.go delete mode 100644 src/lib/os/os_time.go delete mode 100644 src/lib/os/os_types.go create mode 100644 src/lib/os/time.go create mode 100644 src/lib/os/types.go (limited to 'src') diff --git a/src/lib/os/Makefile b/src/lib/os/Makefile index c284b9cc6..ac0d3394d 100644 --- a/src/lib/os/Makefile +++ b/src/lib/os/Makefile @@ -3,8 +3,8 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m os_env.go os_error.go os_file.go os_test.go os_time.go\ -# os_types.go stat_amd64_linux.go dir_amd64_linux.go >Makefile +# gobuild -m dir_amd64_linux.go env.go error.go file.go stat_amd64_linux.go\ +# time.go types.go >Makefile O=6 GC=$(O)g CC=$(O)c -w @@ -33,16 +33,16 @@ coverage: packages $(AS) $*.s O1=\ - os_error.$O\ - os_types.$O\ + error.$O\ + types.$O\ O2=\ - os_env.$O\ - os_time.$O\ + env.$O\ stat_$(GOARCH)_$(GOOS).$O\ + time.$O\ O3=\ - os_file.$O\ + file.$O\ O4=\ dir_$(GOARCH)_$(GOOS).$O\ @@ -50,15 +50,15 @@ O4=\ os.a: a1 a2 a3 a4 a1: $(O1) - $(AR) grc os.a os_error.$O os_types.$O + $(AR) grc os.a error.$O types.$O rm -f $(O1) a2: $(O2) - $(AR) grc os.a os_env.$O os_time.$O stat_$(GOARCH)_$(GOOS).$O + $(AR) grc os.a env.$O stat_$(GOARCH)_$(GOOS).$O time.$O rm -f $(O2) a3: $(O3) - $(AR) grc os.a os_file.$O + $(AR) grc os.a file.$O rm -f $(O3) a4: $(O4) diff --git a/src/lib/os/env.go b/src/lib/os/env.go new file mode 100644 index 000000000..dd4970dea --- /dev/null +++ b/src/lib/os/env.go @@ -0,0 +1,27 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Environment variables. +// Setenv doesn't exist yet: don't have the run-time hooks yet + +package os + +import os "os" + +var ( + ENOENV = NewError("no such environment variable"); +) + +func Getenv(s string) (v string, err *Error) { + n := len(s); + if n == 0 { + return "", EINVAL + } + for i, e := range sys.Envs { + if len(e) > n && e[n] == '=' && e[0:n] == s { + return e[n+1:len(e)], nil + } + } + return "", ENOENV +} diff --git a/src/lib/os/error.go b/src/lib/os/error.go new file mode 100644 index 000000000..63b2dbcca --- /dev/null +++ b/src/lib/os/error.go @@ -0,0 +1,100 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os + +import syscall "syscall" + +// Errors are singleton structures. Use the String() method to get their contents -- +// it handles the nil (no error) case. +type Error struct { + s string +} + +// Indexed by errno. +// If we worry about syscall speed (only relevant on failure), we could +// make it an array, but it's probably not important. +var errorTab = make(map[int64] *Error); + +// Table of all known errors in system. Use the same error string twice, +// get the same *os.Error. +var errorStringTab = make(map[string] *Error); + +// These functions contain a race if two goroutines add identical +// errors simultaneously but the consequences are unimportant. + +// Allocate an Error object, but if it's been seen before, share that one. +func NewError(s string) *Error { + if s == "" { + return nil + } + err, ok := errorStringTab[s]; + if ok { + return err + } + err = &Error{s}; + errorStringTab[s] = err; + return err; +} + +// Allocate an Error objecct, but if it's been seen before, share that one. +func ErrnoToError(errno int64) *Error { + if errno == 0 { + return nil + } + // Quick lookup by errno. + err, ok := errorTab[errno]; + if ok { + return err + } + err = NewError(syscall.Errstr(errno)); + errorTab[errno] = err; + return err; +} + +var ( + ENONE = ErrnoToError(syscall.ENONE); + EPERM = ErrnoToError(syscall.EPERM); + ENOENT = ErrnoToError(syscall.ENOENT); + ESRCH = ErrnoToError(syscall.ESRCH); + EINTR = ErrnoToError(syscall.EINTR); + EIO = ErrnoToError(syscall.EIO); + ENXIO = ErrnoToError(syscall.ENXIO); + E2BIG = ErrnoToError(syscall.E2BIG); + ENOEXEC = ErrnoToError(syscall.ENOEXEC); + EBADF = ErrnoToError(syscall.EBADF); + ECHILD = ErrnoToError(syscall.ECHILD); + EDEADLK = ErrnoToError(syscall.EDEADLK); + ENOMEM = ErrnoToError(syscall.ENOMEM); + EACCES = ErrnoToError(syscall.EACCES); + EFAULT = ErrnoToError(syscall.EFAULT); + ENOTBLK = ErrnoToError(syscall.ENOTBLK); + EBUSY = ErrnoToError(syscall.EBUSY); + EEXIST = ErrnoToError(syscall.EEXIST); + EXDEV = ErrnoToError(syscall.EXDEV); + ENODEV = ErrnoToError(syscall.ENODEV); + ENOTDIR = ErrnoToError(syscall.ENOTDIR); + EISDIR = ErrnoToError(syscall.EISDIR); + EINVAL = ErrnoToError(syscall.EINVAL); + ENFILE = ErrnoToError(syscall.ENFILE); + EMFILE = ErrnoToError(syscall.EMFILE); + ENOTTY = ErrnoToError(syscall.ENOTTY); + ETXTBSY = ErrnoToError(syscall.ETXTBSY); + EFBIG = ErrnoToError(syscall.EFBIG); + ENOSPC = ErrnoToError(syscall.ENOSPC); + ESPIPE = ErrnoToError(syscall.ESPIPE); + EROFS = ErrnoToError(syscall.EROFS); + EMLINK = ErrnoToError(syscall.EMLINK); + EPIPE = ErrnoToError(syscall.EPIPE); + EDOM = ErrnoToError(syscall.EDOM); + ERANGE = ErrnoToError(syscall.ERANGE); + EAGAIN = ErrnoToError(syscall.EAGAIN); +) + +func (e *Error) String() string { + if e == nil { + return "No Error" + } + return e.s +} diff --git a/src/lib/os/file.go b/src/lib/os/file.go new file mode 100644 index 000000000..2a4bc6723 --- /dev/null +++ b/src/lib/os/file.go @@ -0,0 +1,189 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os + +import syscall "syscall" +import os "os" + +// Auxiliary information if the FD describes a directory +type DirInfo struct { // TODO(r): 6g bug means this can't be private + buf []byte; // buffer for directory I/O + nbuf int64; // length of buf; return value from Getdirentries + bufp int64; // location of next record in buf. +} + +// FDs are wrappers for file descriptors +type FD struct { + fd int64; + name string; + dirinfo *DirInfo; // nil unless directory being read +} + +func (fd *FD) Fd() int64 { + return fd.fd +} + +func (fd *FD) Name() string { + return fd.name +} + +func NewFD(fd int64, name string) *FD { + if fd < 0 { + return nil + } + return &FD{fd, name, nil} +} + +var ( + Stdin = NewFD(0, "/dev/stdin"); + Stdout = NewFD(1, "/dev/stdout"); + Stderr = NewFD(2, "/dev/stderr"); +) + +const ( + O_RDONLY = syscall.O_RDONLY; + O_WRONLY = syscall.O_WRONLY; + O_RDWR = syscall.O_RDWR; + O_APPEND = syscall.O_APPEND; + O_ASYNC = syscall.O_ASYNC; + O_CREAT = syscall.O_CREAT; + O_NOCTTY = syscall.O_NOCTTY; + O_NONBLOCK = syscall.O_NONBLOCK; + O_NDELAY = O_NONBLOCK; + O_SYNC = syscall.O_SYNC; + O_TRUNC = syscall.O_TRUNC; +) + +func Open(name string, mode int, flags int) (fd *FD, err *Error) { + r, e := syscall.Open(name, int64(mode), int64(flags)); + return NewFD(r, name), ErrnoToError(e) +} + +func (fd *FD) Close() *Error { + if fd == nil { + return EINVAL + } + r, e := syscall.Close(fd.fd); + fd.fd = -1; // so it can't be closed again + return ErrnoToError(e) +} + +func (fd *FD) Read(b []byte) (ret int, err *Error) { + if fd == nil { + return 0, EINVAL + } + var r, e int64; + if len(b) > 0 { // because we access b[0] + r, e = syscall.Read(fd.fd, &b[0], int64(len(b))); + if r < 0 { + r = 0 + } + } + return int(r), ErrnoToError(e) +} + +func (fd *FD) Write(b []byte) (ret int, err *Error) { + if fd == nil { + return 0, EINVAL + } + var r, e int64; + if len(b) > 0 { // because we access b[0] + r, e = syscall.Write(fd.fd, &b[0], int64(len(b))); + if r < 0 { + r = 0 + } + } + return int(r), ErrnoToError(e) +} + +func (fd *FD) Seek(offset int64, whence int) (ret int64, err *Error) { + r, e := syscall.Seek(fd.fd, offset, int64(whence)); + if e != 0 { + return -1, ErrnoToError(e) + } + if fd.dirinfo != nil && r != 0 { + return -1, ErrnoToError(syscall.EISDIR) + } + return r, nil +} + +func (fd *FD) WriteString(s string) (ret int, err *Error) { + if fd == nil { + return 0, EINVAL + } + r, e := syscall.Write(fd.fd, syscall.StringBytePtr(s), int64(len(s))); + if r < 0 { + r = 0 + } + return int(r), ErrnoToError(e) +} + +func Pipe() (fd1 *FD, fd2 *FD, err *Error) { + var p [2]int64; + r, e := syscall.Pipe(&p); + if e != 0 { + return nil, nil, ErrnoToError(e) + } + return NewFD(p[0], "|0"), NewFD(p[1], "|1"), nil +} + +func Mkdir(name string, perm int) *Error { + r, e := syscall.Mkdir(name, int64(perm)); + return ErrnoToError(e) +} + +func Stat(name string) (dir *Dir, err *Error) { + stat := new(syscall.Stat_t); + r, e := syscall.Stat(name, stat); + if e != 0 { + return nil, ErrnoToError(e) + } + return dirFromStat(name, new(Dir), stat), nil +} + +func Fstat(fd *FD) (dir *Dir, err *Error) { + stat := new(syscall.Stat_t); + r, e := syscall.Fstat(fd.fd, stat); + if e != 0 { + return nil, ErrnoToError(e) + } + return dirFromStat(fd.name, new(Dir), stat), nil +} + +func Lstat(name string) (dir *Dir, err *Error) { + stat := new(syscall.Stat_t); + r, e := syscall.Lstat(name, stat); + if e != 0 { + return nil, ErrnoToError(e) + } + return dirFromStat(name, new(Dir), stat), nil +} + +// Non-portable function defined in operating-system-dependent file. +func Readdirnames(fd *FD, count int) (names []string, err *os.Error) + +// Negative count means read until EOF. +func Readdir(fd *FD, count int) (dirs []Dir, err *os.Error) { + dirname := fd.name; + if dirname == "" { + dirname = "."; + } + dirname += "/"; + names, err1 := Readdirnames(fd, count); + if err1 != nil { + return nil, err1 + } + dirs = make([]Dir, len(names)); + for i, filename := range names { + dirp, err := Stat(dirname + filename); + if dirp == nil || err != nil { + dirs[i].Name = filename // rest is already zeroed out + } else { + dirs[i] = *dirp + } + } + return +} + diff --git a/src/lib/os/os_env.go b/src/lib/os/os_env.go deleted file mode 100644 index dd4970dea..000000000 --- a/src/lib/os/os_env.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Environment variables. -// Setenv doesn't exist yet: don't have the run-time hooks yet - -package os - -import os "os" - -var ( - ENOENV = NewError("no such environment variable"); -) - -func Getenv(s string) (v string, err *Error) { - n := len(s); - if n == 0 { - return "", EINVAL - } - for i, e := range sys.Envs { - if len(e) > n && e[n] == '=' && e[0:n] == s { - return e[n+1:len(e)], nil - } - } - return "", ENOENV -} diff --git a/src/lib/os/os_error.go b/src/lib/os/os_error.go deleted file mode 100644 index 63b2dbcca..000000000 --- a/src/lib/os/os_error.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package os - -import syscall "syscall" - -// Errors are singleton structures. Use the String() method to get their contents -- -// it handles the nil (no error) case. -type Error struct { - s string -} - -// Indexed by errno. -// If we worry about syscall speed (only relevant on failure), we could -// make it an array, but it's probably not important. -var errorTab = make(map[int64] *Error); - -// Table of all known errors in system. Use the same error string twice, -// get the same *os.Error. -var errorStringTab = make(map[string] *Error); - -// These functions contain a race if two goroutines add identical -// errors simultaneously but the consequences are unimportant. - -// Allocate an Error object, but if it's been seen before, share that one. -func NewError(s string) *Error { - if s == "" { - return nil - } - err, ok := errorStringTab[s]; - if ok { - return err - } - err = &Error{s}; - errorStringTab[s] = err; - return err; -} - -// Allocate an Error objecct, but if it's been seen before, share that one. -func ErrnoToError(errno int64) *Error { - if errno == 0 { - return nil - } - // Quick lookup by errno. - err, ok := errorTab[errno]; - if ok { - return err - } - err = NewError(syscall.Errstr(errno)); - errorTab[errno] = err; - return err; -} - -var ( - ENONE = ErrnoToError(syscall.ENONE); - EPERM = ErrnoToError(syscall.EPERM); - ENOENT = ErrnoToError(syscall.ENOENT); - ESRCH = ErrnoToError(syscall.ESRCH); - EINTR = ErrnoToError(syscall.EINTR); - EIO = ErrnoToError(syscall.EIO); - ENXIO = ErrnoToError(syscall.ENXIO); - E2BIG = ErrnoToError(syscall.E2BIG); - ENOEXEC = ErrnoToError(syscall.ENOEXEC); - EBADF = ErrnoToError(syscall.EBADF); - ECHILD = ErrnoToError(syscall.ECHILD); - EDEADLK = ErrnoToError(syscall.EDEADLK); - ENOMEM = ErrnoToError(syscall.ENOMEM); - EACCES = ErrnoToError(syscall.EACCES); - EFAULT = ErrnoToError(syscall.EFAULT); - ENOTBLK = ErrnoToError(syscall.ENOTBLK); - EBUSY = ErrnoToError(syscall.EBUSY); - EEXIST = ErrnoToError(syscall.EEXIST); - EXDEV = ErrnoToError(syscall.EXDEV); - ENODEV = ErrnoToError(syscall.ENODEV); - ENOTDIR = ErrnoToError(syscall.ENOTDIR); - EISDIR = ErrnoToError(syscall.EISDIR); - EINVAL = ErrnoToError(syscall.EINVAL); - ENFILE = ErrnoToError(syscall.ENFILE); - EMFILE = ErrnoToError(syscall.EMFILE); - ENOTTY = ErrnoToError(syscall.ENOTTY); - ETXTBSY = ErrnoToError(syscall.ETXTBSY); - EFBIG = ErrnoToError(syscall.EFBIG); - ENOSPC = ErrnoToError(syscall.ENOSPC); - ESPIPE = ErrnoToError(syscall.ESPIPE); - EROFS = ErrnoToError(syscall.EROFS); - EMLINK = ErrnoToError(syscall.EMLINK); - EPIPE = ErrnoToError(syscall.EPIPE); - EDOM = ErrnoToError(syscall.EDOM); - ERANGE = ErrnoToError(syscall.ERANGE); - EAGAIN = ErrnoToError(syscall.EAGAIN); -) - -func (e *Error) String() string { - if e == nil { - return "No Error" - } - return e.s -} diff --git a/src/lib/os/os_file.go b/src/lib/os/os_file.go deleted file mode 100644 index 2a4bc6723..000000000 --- a/src/lib/os/os_file.go +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package os - -import syscall "syscall" -import os "os" - -// Auxiliary information if the FD describes a directory -type DirInfo struct { // TODO(r): 6g bug means this can't be private - buf []byte; // buffer for directory I/O - nbuf int64; // length of buf; return value from Getdirentries - bufp int64; // location of next record in buf. -} - -// FDs are wrappers for file descriptors -type FD struct { - fd int64; - name string; - dirinfo *DirInfo; // nil unless directory being read -} - -func (fd *FD) Fd() int64 { - return fd.fd -} - -func (fd *FD) Name() string { - return fd.name -} - -func NewFD(fd int64, name string) *FD { - if fd < 0 { - return nil - } - return &FD{fd, name, nil} -} - -var ( - Stdin = NewFD(0, "/dev/stdin"); - Stdout = NewFD(1, "/dev/stdout"); - Stderr = NewFD(2, "/dev/stderr"); -) - -const ( - O_RDONLY = syscall.O_RDONLY; - O_WRONLY = syscall.O_WRONLY; - O_RDWR = syscall.O_RDWR; - O_APPEND = syscall.O_APPEND; - O_ASYNC = syscall.O_ASYNC; - O_CREAT = syscall.O_CREAT; - O_NOCTTY = syscall.O_NOCTTY; - O_NONBLOCK = syscall.O_NONBLOCK; - O_NDELAY = O_NONBLOCK; - O_SYNC = syscall.O_SYNC; - O_TRUNC = syscall.O_TRUNC; -) - -func Open(name string, mode int, flags int) (fd *FD, err *Error) { - r, e := syscall.Open(name, int64(mode), int64(flags)); - return NewFD(r, name), ErrnoToError(e) -} - -func (fd *FD) Close() *Error { - if fd == nil { - return EINVAL - } - r, e := syscall.Close(fd.fd); - fd.fd = -1; // so it can't be closed again - return ErrnoToError(e) -} - -func (fd *FD) Read(b []byte) (ret int, err *Error) { - if fd == nil { - return 0, EINVAL - } - var r, e int64; - if len(b) > 0 { // because we access b[0] - r, e = syscall.Read(fd.fd, &b[0], int64(len(b))); - if r < 0 { - r = 0 - } - } - return int(r), ErrnoToError(e) -} - -func (fd *FD) Write(b []byte) (ret int, err *Error) { - if fd == nil { - return 0, EINVAL - } - var r, e int64; - if len(b) > 0 { // because we access b[0] - r, e = syscall.Write(fd.fd, &b[0], int64(len(b))); - if r < 0 { - r = 0 - } - } - return int(r), ErrnoToError(e) -} - -func (fd *FD) Seek(offset int64, whence int) (ret int64, err *Error) { - r, e := syscall.Seek(fd.fd, offset, int64(whence)); - if e != 0 { - return -1, ErrnoToError(e) - } - if fd.dirinfo != nil && r != 0 { - return -1, ErrnoToError(syscall.EISDIR) - } - return r, nil -} - -func (fd *FD) WriteString(s string) (ret int, err *Error) { - if fd == nil { - return 0, EINVAL - } - r, e := syscall.Write(fd.fd, syscall.StringBytePtr(s), int64(len(s))); - if r < 0 { - r = 0 - } - return int(r), ErrnoToError(e) -} - -func Pipe() (fd1 *FD, fd2 *FD, err *Error) { - var p [2]int64; - r, e := syscall.Pipe(&p); - if e != 0 { - return nil, nil, ErrnoToError(e) - } - return NewFD(p[0], "|0"), NewFD(p[1], "|1"), nil -} - -func Mkdir(name string, perm int) *Error { - r, e := syscall.Mkdir(name, int64(perm)); - return ErrnoToError(e) -} - -func Stat(name string) (dir *Dir, err *Error) { - stat := new(syscall.Stat_t); - r, e := syscall.Stat(name, stat); - if e != 0 { - return nil, ErrnoToError(e) - } - return dirFromStat(name, new(Dir), stat), nil -} - -func Fstat(fd *FD) (dir *Dir, err *Error) { - stat := new(syscall.Stat_t); - r, e := syscall.Fstat(fd.fd, stat); - if e != 0 { - return nil, ErrnoToError(e) - } - return dirFromStat(fd.name, new(Dir), stat), nil -} - -func Lstat(name string) (dir *Dir, err *Error) { - stat := new(syscall.Stat_t); - r, e := syscall.Lstat(name, stat); - if e != 0 { - return nil, ErrnoToError(e) - } - return dirFromStat(name, new(Dir), stat), nil -} - -// Non-portable function defined in operating-system-dependent file. -func Readdirnames(fd *FD, count int) (names []string, err *os.Error) - -// Negative count means read until EOF. -func Readdir(fd *FD, count int) (dirs []Dir, err *os.Error) { - dirname := fd.name; - if dirname == "" { - dirname = "."; - } - dirname += "/"; - names, err1 := Readdirnames(fd, count); - if err1 != nil { - return nil, err1 - } - dirs = make([]Dir, len(names)); - for i, filename := range names { - dirp, err := Stat(dirname + filename); - if dirp == nil || err != nil { - dirs[i].Name = filename // rest is already zeroed out - } else { - dirs[i] = *dirp - } - } - return -} - diff --git a/src/lib/os/os_time.go b/src/lib/os/os_time.go deleted file mode 100644 index 0f5fdfda8..000000000 --- a/src/lib/os/os_time.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package os - -import ( - "os"; - "syscall" -) - -func Time() (sec int64, nsec int64, err *Error) { - var errno int64; - sec, nsec, errno = syscall.Gettimeofday(); - if errno != 0 { - return 0, 0, ErrnoToError(errno) - } - return sec, nsec, nil -} - diff --git a/src/lib/os/os_types.go b/src/lib/os/os_types.go deleted file mode 100644 index 5157dca8e..000000000 --- a/src/lib/os/os_types.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package os - -import "syscall" - -// An operating-system independent representation of Unix data structures. -// OS-specific routines in this directory convert the OS-local versions to these. - -// Result of stat64(2) etc. -type Dir struct { - Dev uint64; - Ino uint64; - Nlink uint64; - Mode uint32; - Uid uint32; - Gid uint32; - Rdev uint64; - Size uint64; - Blksize uint64; - Blocks uint64; - Atime_ns uint64; // nanoseconds since 1970 - Mtime_ns uint64; // nanoseconds since 1970 - Ctime_ns uint64; // nanoseconds since 1970 - Name string; -} - -func (dir *Dir) IsFifo() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO -} - -func (dir *Dir) IsChar() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR -} - -func (dir *Dir) IsDirectory() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR -} - -func (dir *Dir) IsBlock() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK -} - -func (dir *Dir) IsRegular() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG -} - -func (dir *Dir) IsSymlink() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK -} - -func (dir *Dir) IsSocket() bool { - return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK -} - -func (dir *Dir) Permission() int { - return int(dir.Mode & 0777) -} diff --git a/src/lib/os/time.go b/src/lib/os/time.go new file mode 100644 index 000000000..0f5fdfda8 --- /dev/null +++ b/src/lib/os/time.go @@ -0,0 +1,20 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os + +import ( + "os"; + "syscall" +) + +func Time() (sec int64, nsec int64, err *Error) { + var errno int64; + sec, nsec, errno = syscall.Gettimeofday(); + if errno != 0 { + return 0, 0, ErrnoToError(errno) + } + return sec, nsec, nil +} + diff --git a/src/lib/os/types.go b/src/lib/os/types.go new file mode 100644 index 000000000..5157dca8e --- /dev/null +++ b/src/lib/os/types.go @@ -0,0 +1,60 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os + +import "syscall" + +// An operating-system independent representation of Unix data structures. +// OS-specific routines in this directory convert the OS-local versions to these. + +// Result of stat64(2) etc. +type Dir struct { + Dev uint64; + Ino uint64; + Nlink uint64; + Mode uint32; + Uid uint32; + Gid uint32; + Rdev uint64; + Size uint64; + Blksize uint64; + Blocks uint64; + Atime_ns uint64; // nanoseconds since 1970 + Mtime_ns uint64; // nanoseconds since 1970 + Ctime_ns uint64; // nanoseconds since 1970 + Name string; +} + +func (dir *Dir) IsFifo() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO +} + +func (dir *Dir) IsChar() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR +} + +func (dir *Dir) IsDirectory() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR +} + +func (dir *Dir) IsBlock() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK +} + +func (dir *Dir) IsRegular() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG +} + +func (dir *Dir) IsSymlink() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK +} + +func (dir *Dir) IsSocket() bool { + return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK +} + +func (dir *Dir) Permission() int { + return int(dir.Mode & 0777) +} -- cgit v1.2.3