]> Cypherpunks repositories - gostls13.git/commitdiff
Getuid etc.
authorRob Pike <r@golang.org>
Thu, 14 May 2009 23:45:24 +0000 (16:45 -0700)
committerRob Pike <r@golang.org>
Thu, 14 May 2009 23:45:24 +0000 (16:45 -0700)
R=rsc
DELTA=51  (49 added, 0 deleted, 2 changed)
OCL=28859
CL=28859

src/lib/os/Makefile
src/lib/os/user.go [new file with mode: 0644]

index 0334734d1e052367fdc80c9bcd5f7f7b91a1b948..bfcb81dc28f87a645d8876fc9dee087b5eb1d91c 100644 (file)
@@ -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 proc_${GOOS}.go stat_${GOARCH}_${GOOS}.go time.go types.go exec.go >Makefile
+# gobuild -m dir_${GOARCH}_${GOOS}.go env.go error.go file.go proc_${GOOS}.go stat_${GOARCH}_${GOOS}.go time.go types.go exec.go user.go >Makefile
 
 D=
 
@@ -48,6 +48,7 @@ O2=\
        env.$O\
        stat_$(GOARCH)_$(GOOS).$O\
        time.$O\
+       user.$O\
 
 O3=\
        file.$O\
@@ -65,7 +66,7 @@ a1: $(O1)
        rm -f $(O1)
 
 a2: $(O2)
-       $(AR) grc _obj$D/os.a env.$O stat_$(GOARCH)_$(GOOS).$O time.$O
+       $(AR) grc _obj$D/os.a env.$O stat_$(GOARCH)_$(GOOS).$O time.$O user.$O
        rm -f $(O2)
 
 a3: $(O3)
diff --git a/src/lib/os/user.go b/src/lib/os/user.go
new file mode 100644 (file)
index 0000000..abb665b
--- /dev/null
@@ -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
+}
+