summaryrefslogtreecommitdiff
path: root/src/lib/os/user.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-05-14 16:45:24 -0700
committerRob Pike <r@golang.org>2009-05-14 16:45:24 -0700
commitc357d95aa02be8fe3b5eedfc00884f0bd1f9f287 (patch)
treeba66ec7eeee4b2503b0e7fee4ff0172871855606 /src/lib/os/user.go
parent2fa7b7cd6b7882c46d8972a5a83c78fa76435278 (diff)
downloadgolang-c357d95aa02be8fe3b5eedfc00884f0bd1f9f287.tar.gz
Getuid etc.
R=rsc DELTA=51 (49 added, 0 deleted, 2 changed) OCL=28859 CL=28859
Diffstat (limited to 'src/lib/os/user.go')
-rw-r--r--src/lib/os/user.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/os/user.go b/src/lib/os/user.go
new file mode 100644
index 000000000..abb665b30
--- /dev/null
+++ b/src/lib/os/user.go
@@ -0,0 +1,49 @@
+// 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";
+)
+
+// Getuid returns the numeric user id of the caller.
+func Getuid() (uid int, err Error) {
+ u, _, e := syscall.Syscall(syscall.SYS_GETUID, 0, 0, 0);
+ if e != 0 {
+ return -1, ErrnoToError(e)
+ }
+ return int(u), nil
+}
+
+// Geteuid returns the numeric effective user id of the caller.
+func Geteuid() (uid int, err Error) {
+ u, _, e := syscall.Syscall(syscall.SYS_GETEUID, 0, 0, 0);
+ if e != 0 {
+ return -1, ErrnoToError(e)
+ }
+ return int(u), nil
+}
+
+// Getgid returns the numeric group id of the caller.
+func Getgid() (uid int, err Error) {
+ g, _, e := syscall.Syscall(syscall.SYS_GETGID, 0, 0, 0);
+ if e != 0 {
+ return -1, ErrnoToError(e)
+ }
+ return int(g), nil
+}
+
+// Getegid returns the numeric effective group id of the caller.
+func Getegid() (uid int, err Error) {
+ g, _, e := syscall.Syscall(syscall.SYS_GETEGID, 0, 0, 0);
+ if e != 0 {
+ return -1, ErrnoToError(e)
+ }
+ return int(g), nil
+}
+