...
Source file
src/os/user/lookup_stubs.go
Documentation: os/user
1
2
3
4
5
6
7 package user
8
9 import (
10 "errors"
11 "fmt"
12 "os"
13 "runtime"
14 "strconv"
15 )
16
17 func init() {
18 groupImplemented = false
19 }
20
21 func current() (*User, error) {
22 u := &User{
23 Uid: currentUID(),
24 Gid: currentGID(),
25 Username: os.Getenv("USER"),
26 Name: "",
27 HomeDir: os.Getenv("HOME"),
28 }
29
30 switch runtime.GOOS {
31 case "nacl":
32 if u.Uid == "" {
33 u.Uid = "1"
34 }
35 if u.Username == "" {
36 u.Username = "nacl"
37 }
38 if u.HomeDir == "" {
39 u.HomeDir = "/"
40 }
41 case "android":
42 if u.Uid == "" {
43 u.Uid = "1"
44 }
45 if u.Username == "" {
46 u.Username = "android"
47 }
48 if u.HomeDir == "" {
49 u.HomeDir = "/sdcard"
50 }
51 }
52
53
54 if u.Uid != "" && u.Username != "" && u.HomeDir != "" {
55 return u, nil
56 }
57 return u, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
58 }
59
60 func listGroups(*User) ([]string, error) {
61 if runtime.GOOS == "android" {
62 return nil, errors.New("user: GroupIds not implemented on Android")
63 }
64 return nil, errors.New("user: GroupIds requires cgo")
65 }
66
67 func currentUID() string {
68 if id := os.Getuid(); id >= 0 {
69 return strconv.Itoa(id)
70 }
71
72
73
74 return ""
75 }
76
77 func currentGID() string {
78 if id := os.Getgid(); id >= 0 {
79 return strconv.Itoa(id)
80 }
81 return ""
82 }
83
View as plain text