diff options
| author | Russ Cox <rsc@golang.org> | 2009-06-01 22:14:39 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-06-01 22:14:39 -0700 |
| commit | 9849d463b66c597d5e2429274e677030c4465484 (patch) | |
| tree | 874da14a9428e632f5d373e713631be06c233e65 /src/lib/os | |
| parent | 8f6dc671ffef2fc05c938ba6dee40a0354e83bbd (diff) | |
| download | golang-9849d463b66c597d5e2429274e677030c4465484.tar.gz | |
update Go tree to use new syscall package.
R=r
DELTA=713 (109 added, 386 deleted, 218 changed)
OCL=29707
CL=29722
Diffstat (limited to 'src/lib/os')
| -rw-r--r-- | src/lib/os/Makefile | 13 | ||||
| -rw-r--r-- | src/lib/os/dir_amd64_darwin.go | 20 | ||||
| -rw-r--r-- | src/lib/os/dir_amd64_linux.go | 10 | ||||
| -rw-r--r-- | src/lib/os/error.go | 5 | ||||
| -rw-r--r-- | src/lib/os/exec.go | 8 | ||||
| -rw-r--r-- | src/lib/os/file.go | 107 | ||||
| -rw-r--r-- | src/lib/os/proc.go | 50 | ||||
| -rw-r--r-- | src/lib/os/proc_darwin.go | 20 | ||||
| -rw-r--r-- | src/lib/os/stat_amd64_darwin.go | 10 | ||||
| -rw-r--r-- | src/lib/os/stat_amd64_linux.go | 6 | ||||
| -rw-r--r-- | src/lib/os/time.go | 7 | ||||
| -rw-r--r-- | src/lib/os/user.go | 64 |
12 files changed, 137 insertions, 183 deletions
diff --git a/src/lib/os/Makefile b/src/lib/os/Makefile index 50a06d92b..5272e88ad 100644 --- a/src/lib/os/Makefile +++ b/src/lib/os/Makefile @@ -3,7 +3,7 @@ # license that can be found in the LICENSE file. # DO NOT EDIT. Automatically generated by gobuild. -# gobuild -m dir_${GOARCH}_${GOOS}.go env.go error.go file.go path.go proc_${GOOS}.go stat_${GOARCH}_${GOOS}.go time.go types.go exec.go user.go getwd.go >Makefile +# gobuild -m dir_${GOARCH}_${GOOS}.go env.go error.go file.go path.go stat_${GOARCH}_${GOOS}.go time.go types.go exec.go proc.go getwd.go >Makefile D= @@ -41,16 +41,15 @@ coverage: packages O1=\ error.$O\ - proc_$(GOOS).$O\ types.$O\ O2=\ - env.$O\ + proc.$O\ stat_$(GOARCH)_$(GOOS).$O\ time.$O\ - user.$O\ O3=\ + env.$O\ file.$O\ O4=\ @@ -64,15 +63,15 @@ phases: a1 a2 a3 a4 _obj$D/os.a: phases a1: $(O1) - $(AR) grc _obj$D/os.a error.$O proc_$(GOOS).$O types.$O + $(AR) grc _obj$D/os.a error.$O types.$O rm -f $(O1) a2: $(O2) - $(AR) grc _obj$D/os.a env.$O stat_$(GOARCH)_$(GOOS).$O time.$O user.$O + $(AR) grc _obj$D/os.a proc.$O stat_$(GOARCH)_$(GOOS).$O time.$O rm -f $(O2) a3: $(O3) - $(AR) grc _obj$D/os.a file.$O + $(AR) grc _obj$D/os.a env.$O file.$O rm -f $(O3) a4: $(O4) diff --git a/src/lib/os/dir_amd64_darwin.go b/src/lib/os/dir_amd64_darwin.go index 681a710d1..2803ecee2 100644 --- a/src/lib/os/dir_amd64_darwin.go +++ b/src/lib/os/dir_amd64_darwin.go @@ -32,25 +32,31 @@ func readdirnames(file *File, count int) (names []string, err Error) { for count != 0 { // Refill the buffer if necessary if d.bufp >= d.nbuf { - var errno int64; - // Final argument is (basep *int64) and the syscall doesn't take nil. - d.nbuf, errno = syscall.Getdirentries(file.fd, &d.buf[0], int64(len(d.buf)), new(int64)); - if d.nbuf < 0 { + var errno int; + d.bufp = 0; + // Final argument is (basep *uintptr) and the syscall doesn't take nil. + d.nbuf, errno = syscall.Getdirentries(file.fd, d.buf, new(uintptr)); + if errno != 0 { + d.nbuf = 0; return names, ErrnoToError(errno) } if d.nbuf == 0 { break // EOF } - d.bufp = 0; } // Drain the buffer for count != 0 && d.bufp < d.nbuf { dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); - d.bufp += int64(dirent.Reclen); + if dirent.Reclen == 0 { + d.bufp = d.nbuf; + break + } + d.bufp += int(dirent.Reclen); if dirent.Ino == 0 { // File absent in directory. continue } - var name = string(dirent.Name[0:dirent.Namlen]); + bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); + var name = string(bytes[0:dirent.Namlen]); if name == "." || name == ".." { // Useless names continue } diff --git a/src/lib/os/dir_amd64_linux.go b/src/lib/os/dir_amd64_linux.go index 67eae30ff..05b3d4c65 100644 --- a/src/lib/os/dir_amd64_linux.go +++ b/src/lib/os/dir_amd64_linux.go @@ -41,9 +41,8 @@ func readdirnames(file *File, count int) (names []string, err Error) { for count != 0 { // Refill the buffer if necessary if d.bufp >= d.nbuf { - var errno int64; - dbuf := (*syscall.Dirent)(unsafe.Pointer(&d.buf[0])); - d.nbuf, errno = syscall.Getdents(file.fd, dbuf, int64(len(d.buf))); + var errno int; + d.nbuf, errno = syscall.Getdents(file.fd, d.buf); if d.nbuf < 0 { return names, ErrnoToError(errno) } @@ -55,11 +54,12 @@ func readdirnames(file *File, count int) (names []string, err Error) { // Drain the buffer for count != 0 && d.bufp < d.nbuf { dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); - d.bufp += int64(dirent.Reclen); + d.bufp += int(dirent.Reclen); if dirent.Ino == 0 { // File absent in directory. continue } - var name = string(dirent.Name[0:clen(&dirent.Name)]); + bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); + var name = string(bytes[0:clen(bytes)]); if name == "." || name == ".." { // Useless names continue } diff --git a/src/lib/os/error.go b/src/lib/os/error.go index 778465627..718499b21 100644 --- a/src/lib/os/error.go +++ b/src/lib/os/error.go @@ -27,12 +27,12 @@ func NewError(s string) Error { // wrappers to convert the error number into an Error. type Errno int64 func (e Errno) String() string { - return syscall.Errstr(int64(e)) + return syscall.Errstr(int(e)) } // ErrnoToError converts errno to an Error (underneath, an Errno). // It returns nil for the "no error" errno. -func ErrnoToError(errno int64) Error { +func ErrnoToError(errno int) Error { if errno == 0 { return nil } @@ -41,7 +41,6 @@ func ErrnoToError(errno int64) Error { // Commonly known Unix errors. var ( - ENONE Error = Errno(syscall.ENONE); EPERM Error = Errno(syscall.EPERM); ENOENT Error = Errno(syscall.ENOENT); ESRCH Error = Errno(syscall.ESRCH); diff --git a/src/lib/os/exec.go b/src/lib/os/exec.go index 9f0f01e0a..d283c7267 100644 --- a/src/lib/os/exec.go +++ b/src/lib/os/exec.go @@ -20,7 +20,7 @@ func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*File (pid int, err Error) { // Create array of integer (system) fds. - intfd := make([]int64, len(fd)); + intfd := make([]int, len(fd)); for i, f := range(fd) { if f == nil { intfd[i] = -1; @@ -64,20 +64,20 @@ const ( WNOHANG = syscall.WNOHANG; // Don't wait if no process has exited. WSTOPPED = syscall.WSTOPPED; // If set, status of stopped subprocesses is also reported. WUNTRACED = WSTOPPED; - WRUSAGE = 1<<60; // Record resource usage. + WRUSAGE = 1<<30; // Record resource usage. ) // Wait waits for process pid to exit or stop, and then returns a // Waitmsg describing its status and an Error, if any. The options // (WNOHANG etc.) affect the behavior of the Wait call. -func Wait(pid int, options uint64) (w *Waitmsg, err Error) { +func Wait(pid int, options int) (w *Waitmsg, err Error) { var status syscall.WaitStatus; var rusage *syscall.Rusage; if options & WRUSAGE != 0 { rusage = new(syscall.Rusage); options ^= WRUSAGE; } - pid1, e := syscall.Wait4(int64(pid), &status, int64(options), rusage); + pid1, e := syscall.Wait4(pid, &status, options, rusage); if e != 0 { return nil, ErrnoToError(e); } diff --git a/src/lib/os/file.go b/src/lib/os/file.go index 7aa6632c7..1562b1b0e 100644 --- a/src/lib/os/file.go +++ b/src/lib/os/file.go @@ -14,20 +14,20 @@ import ( // Auxiliary information if the File describes a directory type dirInfo struct { buf []byte; // buffer for directory I/O - nbuf int64; // length of buf; return value from Getdirentries - bufp int64; // location of next record in buf. + nbuf int; // length of buf; return value from Getdirentries + bufp int; // location of next record in buf. } // File represents an open file descriptor. type File struct { - fd int64; + fd int; name string; dirinfo *dirInfo; // nil unless directory being read nepipe int; // number of consecutive EPIPE in Write } // Fd returns the integer Unix file descriptor referencing the open file. -func (file *File) Fd() int64 { +func (file *File) Fd() int { return file.fd } @@ -37,7 +37,7 @@ func (file *File) Name() string { } // NewFile returns a new File with the given file descriptor and name. -func NewFile(file int64, name string) *File { +func NewFile(file int, name string) *File { if file < 0 { return nil } @@ -72,7 +72,7 @@ const ( // if applicable. If successful, methods on the returned File can be used for I/O. // It returns the File and an Error, if any. func Open(name string, flag int, perm int) (file *File, err Error) { - r, e := syscall.Open(name, int64(flag | syscall.O_CLOEXEC), int64(perm)); + r, e := syscall.Open(name, flag | syscall.O_CLOEXEC, perm); if e != 0 { return nil, ErrnoToError(e); } @@ -92,9 +92,9 @@ func (file *File) Close() Error { if file == nil { return EINVAL } - r, e := syscall.Close(file.fd); + err := ErrnoToError(syscall.Close(file.fd)); file.fd = -1; // so it can't be closed again - return ErrnoToError(e) + return err; } // Read reads up to len(b) bytes from the File. @@ -105,14 +105,11 @@ func (file *File) Read(b []byte) (ret int, err Error) { if file == nil { return 0, EINVAL } - var r, e int64; - if len(b) > 0 { // because we access b[0] - r, e = syscall.Read(file.fd, &b[0], int64(len(b))); - if r < 0 { - r = 0 - } + n, e := syscall.Read(file.fd, b); + if n < 0 { + n = 0; } - return int(r), ErrnoToError(e) + return n, ErrnoToError(e); } // Write writes len(b) bytes to the File. @@ -122,12 +119,9 @@ func (file *File) Write(b []byte) (ret int, err Error) { if file == nil { return 0, EINVAL } - var r, e int64; - if len(b) > 0 { // because we access b[0] - r, e = syscall.Write(file.fd, &b[0], int64(len(b))); - if r < 0 { - r = 0 - } + n, e := syscall.Write(file.fd, b); + if n < 0 { + n = 0 } if e == syscall.EPIPE { file.nepipe++; @@ -137,7 +131,7 @@ func (file *File) Write(b []byte) (ret int, err Error) { } else { file.nepipe = 0; } - return int(r), ErrnoToError(e) + return n, ErrnoToError(e) } // Seek sets the offset for the next Read or Write on file to offset, interpreted @@ -145,7 +139,7 @@ func (file *File) Write(b []byte) (ret int, err Error) { // relative to the current offset, and 2 means relative to the end. // It returns the new offset and an Error, if any. func (file *File) Seek(offset int64, whence int) (ret int64, err Error) { - r, e := syscall.Seek(file.fd, offset, int64(whence)); + r, e := syscall.Seek(file.fd, offset, whence); if e != 0 { return -1, ErrnoToError(e) } @@ -161,7 +155,9 @@ func (file *File) WriteString(s string) (ret int, err Error) { if file == nil { return 0, EINVAL } - r, e := syscall.Write(file.fd, syscall.StringBytePtr(s), int64(len(s))); + b := syscall.StringByteSlice(s); + b = b[0:len(b)-1]; + r, e := syscall.Write(file.fd, b); if r < 0 { r = 0 } @@ -171,11 +167,11 @@ func (file *File) WriteString(s string) (ret int, err Error) { // Pipe returns a connected pair of Files; reads from r return bytes written to w. // It returns the files and an Error, if any. func Pipe() (r *File, w *File, err Error) { - var p [2]int64; + var p [2]int; // See ../syscall/exec.go for description of lock. syscall.ForkLock.RLock(); - ret, e := syscall.Pipe(&p); + e := syscall.Pipe(&p); if e != 0 { syscall.ForkLock.RUnlock(); return nil, nil, ErrnoToError(e) @@ -190,8 +186,7 @@ func Pipe() (r *File, w *File, err Error) { // Mkdir creates a new directory with the specified name and permission bits. // It returns an error, if any. func Mkdir(name string, perm int) Error { - r, e := syscall.Mkdir(name, int64(perm)); - return ErrnoToError(e) + return ErrnoToError(syscall.Mkdir(name, perm)); } // Stat returns a Dir structure describing the named file and an error, if any. @@ -201,13 +196,13 @@ func Mkdir(name string, perm int) Error { // the link itself and has dir.FollowedSymlink set to false. func Stat(name string) (dir *Dir, err Error) { var lstat, stat syscall.Stat_t; - r, e := syscall.Lstat(name, &lstat); + e := syscall.Lstat(name, &lstat); if e != 0 { return nil, ErrnoToError(e); } statp := &lstat; if lstat.Mode & syscall.S_IFMT == syscall.S_IFLNK { - r, e := syscall.Stat(name, &stat); + e := syscall.Stat(name, &stat); if e == 0 { statp = &stat; } @@ -219,7 +214,7 @@ func Stat(name string) (dir *Dir, err Error) { // It returns the Dir and an error, if any. func (file *File) Stat() (dir *Dir, err Error) { var stat syscall.Stat_t; - r, e := syscall.Fstat(file.fd, &stat); + e := syscall.Fstat(file.fd, &stat); if e != 0 { return nil, ErrnoToError(e) } @@ -231,7 +226,7 @@ func (file *File) Stat() (dir *Dir, err Error) { // symbolic link. Lstat makes no attempt to follow the link. func Lstat(name string) (dir *Dir, err Error) { var stat syscall.Stat_t; - r, e := syscall.Lstat(name, &stat); + e := syscall.Lstat(name, &stat); if e != 0 { return nil, ErrnoToError(e) } @@ -280,15 +275,13 @@ func (file *File) Readdir(count int) (dirs []Dir, err Error) { // Chdir changes the current working directory to the named directory. func Chdir(dir string) Error { - r, e := syscall.Chdir(dir); - return ErrnoToError(e); + return ErrnoToError(syscall.Chdir(dir)); } // Chdir changes the current working directory to the file, // which must be a directory. func (f *File) Chdir() Error { - r, e := syscall.Fchdir(f.fd); - return ErrnoToError(e); + return ErrnoToError(syscall.Fchdir(f.fd)); } // Remove removes the named file or directory. @@ -297,11 +290,11 @@ func Remove(name string) Error { // whether name is a file or directory. // Try both: it is cheaper on average than // doing a Stat plus the right one. - r, e := syscall.Unlink(name); + e := syscall.Unlink(name); if e == 0 { return nil; } - r1, e1 := syscall.Rmdir(name); + e1 := syscall.Rmdir(name); if e1 == 0 { return nil; } @@ -323,26 +316,25 @@ func Remove(name string) Error { // Link creates a hard link. func Link(oldname, newname string) Error { - r, e := syscall.Link(oldname, newname); - return ErrnoToError(e); + return ErrnoToError(syscall.Link(oldname, newname)); } // Symlink creates a symbolic link. func Symlink(oldname, newname string) Error { - r, e := syscall.Symlink(oldname, newname); - return ErrnoToError(e); + return ErrnoToError(syscall.Symlink(oldname, newname)); } // Readlink reads the contents of a symbolic link: the destination of // the link. It returns the contents and an Error, if any. func Readlink(name string) (string, Error) { - for len := int64(128); ; len *= 2 { + for len := 128; ; len *= 2 { b := make([]byte, len); - r, e := syscall.Readlink(name, &b[0], len); - if r == -1 { + n, e := syscall.Readlink(name, b); + if e != 0 { return "", ErrnoToError(e); - } else if r < len { - return string(b[0:r]), nil; + } + if n < len { + return string(b[0:n]), nil; } } // Silence 6g. @@ -352,47 +344,40 @@ func Readlink(name string) (string, Error) { // Chmod changes the mode of the named file to mode. // If the file is a symbolic link, it changes the uid and gid of the link's target. func Chmod(name string, mode int) Error { - r, e := syscall.Chmod(name, int64(mode)); - return ErrnoToError(e); + return ErrnoToError(syscall.Chmod(name, mode)); } // Chmod changes the mode of the file to mode. func (f *File) Chmod(mode int) Error { - r, e := syscall.Fchmod(f.fd, int64(mode)); - return ErrnoToError(e); + return ErrnoToError(syscall.Fchmod(f.fd, mode)); } // 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. func Chown(name string, uid, gid int) Error { - r, e := syscall.Chown(name, int64(uid), int64(gid)); - return ErrnoToError(e); + return ErrnoToError(syscall.Chown(name, uid, gid)); } // 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. func Lchown(name string, uid, gid int) Error { - r, e := syscall.Lchown(name, int64(uid), int64(gid)); - return ErrnoToError(e); + return ErrnoToError(syscall.Lchown(name, uid, gid)); } // Chown changes the numeric uid and gid of the named file. func (f *File) Chown(uid, gid int) Error { - r, e := syscall.Fchown(f.fd, int64(uid), int64(gid)); - return ErrnoToError(e); + return ErrnoToError(syscall.Fchown(f.fd, uid, gid)); } // Truncate changes the size of the named file. // If the file is a symbolic link, it changes the size of the link's target. func Truncate(name string, size int64) Error { - r, e := syscall.Truncate(name, size); - return ErrnoToError(e); + return ErrnoToError(syscall.Truncate(name, size)); } // Truncate changes the size of the file. // It does not change the I/O offset. func (f *File) Truncate(size int64) Error { - r, e := syscall.Ftruncate(f.fd, size); - return ErrnoToError(e); + return ErrnoToError(syscall.Ftruncate(f.fd, size)); } diff --git a/src/lib/os/proc.go b/src/lib/os/proc.go new file mode 100644 index 000000000..d2fd6493e --- /dev/null +++ b/src/lib/os/proc.go @@ -0,0 +1,50 @@ +// 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. + +// Process etc. + +package os + +import ( + "syscall"; + "os"; + "unsafe"; +) + +var Args []string; // provided by runtime +var Envs []string; // provided by runtime + + +// Getuid returns the numeric user id of the caller. +func Getuid() int { + return syscall.Getuid(); +} + +// Geteuid returns the numeric effective user id of the caller. +func Geteuid() int { + return syscall.Geteuid(); +} + +// Getgid returns the numeric group id of the caller. +func Getgid() int { + return syscall.Getgid(); +} + +// Getegid returns the numeric effective group id of the caller. +func Getegid() int { + return syscall.Getegid(); +} + +// Getgroups returns a list of the numeric ids of groups that the caller belongs to. +func Getgroups() ([]int, os.Error) { + gids, errno := syscall.Getgroups(); + return gids, ErrnoToError(errno); +} + +// Exit causes the current program to exit with the given status code. +// Conventionally, code zero indicates success, non-zero an error. +func Exit(code int) { + syscall.Exit(code); +} + diff --git a/src/lib/os/proc_darwin.go b/src/lib/os/proc_darwin.go deleted file mode 100644 index bae977b1f..000000000 --- a/src/lib/os/proc_darwin.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"; -) - -var Args []string; // provided by runtime -var Envs []string; // provided by runtime - -// Exit causes the current program to exit with the given status code. -// Conventionally, code zero indicates success, non-zero an error. -func Exit(code int) { - syscall.Syscall(syscall.SYS_EXIT, int64(code), 0, 0) -} - diff --git a/src/lib/os/stat_amd64_darwin.go b/src/lib/os/stat_amd64_darwin.go index e72d76f91..1771ca160 100644 --- a/src/lib/os/stat_amd64_darwin.go +++ b/src/lib/os/stat_amd64_darwin.go @@ -21,12 +21,12 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { dir.Uid = stat.Uid; dir.Gid = stat.Gid; dir.Rdev = uint64(stat.Rdev); - dir.Size = stat.Size; + dir.Size = uint64(stat.Size); dir.Blksize = uint64(stat.Blksize); - dir.Blocks = stat.Blocks; - dir.Atime_ns = uint64(stat.Atime.Sec) * 1e9 + stat.Atime.Nsec; - dir.Mtime_ns = uint64(stat.Mtime.Sec) * 1e9 + stat.Mtime.Nsec; - dir.Ctime_ns = uint64(stat.Ctime.Sec) * 1e9 + stat.Atime.Nsec; + dir.Blocks = uint64(stat.Blocks); + dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec)); + dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec)); + dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec)); for i := len(name) - 1; i >= 0; i-- { if name[i] == '/' { name = name[i+1:len(name)]; diff --git a/src/lib/os/stat_amd64_linux.go b/src/lib/os/stat_amd64_linux.go index e1beb1666..9b3018178 100644 --- a/src/lib/os/stat_amd64_linux.go +++ b/src/lib/os/stat_amd64_linux.go @@ -24,9 +24,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { dir.Size = uint64(stat.Size); dir.Blksize = uint64(stat.Blksize); dir.Blocks = uint64(stat.Blocks); - dir.Atime_ns = uint64(stat.Atime.Sec) * 1e9 + stat.Atime.Nsec; - dir.Mtime_ns = uint64(stat.Mtime.Sec) * 1e9 + stat.Mtime.Nsec; - dir.Ctime_ns = uint64(stat.Ctime.Sec) * 1e9 + stat.Atime.Nsec; + dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)); + dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)); + dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)); for i := len(name) - 1; i >= 0; i-- { if name[i] == '/' { name = name[i+1:len(name)]; diff --git a/src/lib/os/time.go b/src/lib/os/time.go index 7e268a0c7..3eee243cc 100644 --- a/src/lib/os/time.go +++ b/src/lib/os/time.go @@ -15,11 +15,10 @@ import ( // time is thus 1e9*sec+nsec, in nanoseconds. The zero of // time is the Unix epoch. func Time() (sec int64, nsec int64, err Error) { - var errno int64; - sec, nsec, errno = syscall.Gettimeofday(); - if errno != 0 { + var tv syscall.Timeval; + if errno := syscall.Gettimeofday(&tv); errno != 0 { return 0, 0, ErrnoToError(errno) } - return sec, nsec, nil + return int64(tv.Sec), int64(tv.Usec)*1000, err; } diff --git a/src/lib/os/user.go b/src/lib/os/user.go deleted file mode 100644 index 194aa50e4..000000000 --- a/src/lib/os/user.go +++ /dev/null @@ -1,64 +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. - -// User ids etc. - -package os - -import ( - "syscall"; - "os"; - "unsafe"; -) - -// Getuid returns the numeric user id of the caller. -func Getuid() int { - u, r2, e := syscall.Syscall(syscall.SYS_GETUID, 0, 0, 0); - return int(u); -} - -// Geteuid returns the numeric effective user id of the caller. -func Geteuid() int { - u, r2, e := syscall.Syscall(syscall.SYS_GETEUID, 0, 0, 0); - return int(u); -} - -// Getgid returns the numeric group id of the caller. -func Getgid() int { - g, r2, e := syscall.Syscall(syscall.SYS_GETGID, 0, 0, 0); - return int(g); -} - -// Getegid returns the numeric effective group id of the caller. -func Getegid() int { - g, r2, e := syscall.Syscall(syscall.SYS_GETEGID, 0, 0, 0); - return int(g); -} - -// Getgroups returns a list of the numeric ids of groups that the caller belongs to. -func Getgroups() ([]int, os.Error) { - // first call asks how many there are. - r1, r2, err := syscall.Syscall(syscall.SYS_GETGROUPS, 0, 0, 0); - if err != 0 { - return nil, ErrnoToError(err); - } - - // Sanity check group count. - // On Linux, max is 1<<16; on BSD, OS X, max is 16. - if r1 < 0 || r1 > 1<<20 { - return nil, EINVAL; - } - a := make([]int, r1); - if r1 > 0 { - tmp := make([]uint32, r1); - r1, r2, err = syscall.Syscall(syscall.SYS_GETGROUPS, r1, int64(uintptr(unsafe.Pointer(&tmp[0]))), 0); - if err != 0 { - return nil, ErrnoToError(err); - } - for i := 0; i < len(a); i++ { - a[i] = int(tmp[i]); - } - } - return a[0:r1], nil; -} |
