Commit 178c8578 authored by Anthony Martin's avatar Anthony Martin

os/user: update stub documentation

R=golang-dev, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/6844088
parent 4ce3df50
// Copyright 2011 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 user
// Current returns the current user.
func Current() (*User, error) {
return current()
}
// Lookup looks up a user by username. If the user cannot be found, the
// returned error is of type UnknownUserError.
func Lookup(username string) (*User, error) {
return lookup(username)
}
// LookupId looks up a user by userid. If the user cannot be found, the
// returned error is of type UnknownUserIdError.
func LookupId(uid string) (*User, error) {
return lookupId(uid)
}
......@@ -15,14 +15,14 @@ func init() {
implemented = false
}
func Current() (*User, error) {
func current() (*User, error) {
return nil, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
}
func Lookup(username string) (*User, error) {
func lookup(username string) (*User, error) {
return nil, fmt.Errorf("user: Lookup not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
}
func LookupId(string) (*User, error) {
func lookupId(uid string) (*User, error) {
return nil, fmt.Errorf("user: LookupId not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
}
......@@ -29,28 +29,23 @@ static int mygetpwuid_r(int uid, struct passwd *pwd,
*/
import "C"
// Current returns the current user.
func Current() (*User, error) {
return lookup(syscall.Getuid(), "", false)
func current() (*User, error) {
return lookupUnix(syscall.Getuid(), "", false)
}
// Lookup looks up a user by username. If the user cannot be found,
// the returned error is of type UnknownUserError.
func Lookup(username string) (*User, error) {
return lookup(-1, username, true)
func lookup(username string) (*User, error) {
return lookupUnix(-1, username, true)
}
// LookupId looks up a user by userid. If the user cannot be found,
// the returned error is of type UnknownUserIdError.
func LookupId(uid string) (*User, error) {
func lookupId(uid string) (*User, error) {
i, e := strconv.Atoi(uid)
if e != nil {
return nil, e
}
return lookup(i, "", false)
return lookupUnix(i, "", false)
}
func lookup(uid int, username string, lookupByName bool) (*User, error) {
func lookupUnix(uid int, username string, lookupByName bool) (*User, error) {
var pwd C.struct_passwd
var result *C.struct_passwd
......
......@@ -68,8 +68,7 @@ func newUser(usid *syscall.SID, gid, dir string) (*User, error) {
return u, nil
}
// Current returns the current user.
func Current() (*User, error) {
func current() (*User, error) {
t, e := syscall.OpenCurrentProcessToken()
if e != nil {
return nil, e
......@@ -103,8 +102,7 @@ func newUserFromSid(usid *syscall.SID) (*User, error) {
return newUser(usid, gid, dir)
}
// Lookup looks up a user by username.
func Lookup(username string) (*User, error) {
func lookup(username string) (*User, error) {
sid, _, t, e := syscall.LookupSID("", username)
if e != nil {
return nil, e
......@@ -115,8 +113,7 @@ func Lookup(username string) (*User, error) {
return newUserFromSid(sid)
}
// LookupId looks up a user by userid.
func LookupId(uid string) (*User, error) {
func lookupId(uid string) (*User, error) {
sid, e := syscall.StringToSid(uid)
if e != nil {
return nil, e
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment