...
Source file
src/os/user/lookup_stubs.go
Documentation: os/user
package user
import (
"errors"
"fmt"
"os"
"runtime"
"strconv"
)
func init() {
groupImplemented = false
}
func current() (*User, error) {
u := &User{
Uid: currentUID(),
Gid: currentGID(),
Username: os.Getenv("USER"),
Name: "",
HomeDir: os.Getenv("HOME"),
}
switch runtime.GOOS {
case "nacl":
if u.Uid == "" {
u.Uid = "1"
}
if u.Username == "" {
u.Username = "nacl"
}
if u.HomeDir == "" {
u.HomeDir = "/"
}
case "android":
if u.Uid == "" {
u.Uid = "1"
}
if u.Username == "" {
u.Username = "android"
}
if u.HomeDir == "" {
u.HomeDir = "/sdcard"
}
}
if u.Uid != "" && u.Username != "" && u.HomeDir != "" {
return u, nil
}
return u, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
}
func listGroups(*User) ([]string, error) {
if runtime.GOOS == "android" {
return nil, errors.New("user: GroupIds not implemented on Android")
}
return nil, errors.New("user: GroupIds requires cgo")
}
func currentUID() string {
if id := os.Getuid(); id >= 0 {
return strconv.Itoa(id)
}
return ""
}
func currentGID() string {
if id := os.Getgid(); id >= 0 {
return strconv.Itoa(id)
}
return ""
}
View as plain text