예제 #1
0
파일: pwd.go 프로젝트: Maki-Daisuke/go-pwd
// Getpwents returns all entries in the user databases.
// This is aimed to be thread-safe, that is, if a goroutine is executing this
// function, another goroutine is blocked until it completes.
func Getpwents() []*Passwd {
	pwentMutex.Lock()
	defer pwentMutex.Unlock()
	C.setpwent()
	defer C.endpwent()
	ents := make([]*Passwd, 0, 10)
	for {
		cpw := C.getpwent()
		if cpw == nil {
			break
		}
		ents = append(ents, cpasswd2go(cpw))
	}
	return ents
}
예제 #2
0
파일: users.go 프로젝트: fimmtiu/gofingerd
// Returns a list of all users on the system.
func ListAllUsers() ([]User, error) {
	users := []User{}
	for {
		pwent, err := C.getpwent()
		if pwent == nil {
			if err != nil {
				return nil, err
			} else {
				break
			}
		}
		users = append(users, pwentToUser(pwent))
	}
	C.endpwent()
	return users, nil
}