libgo: update Hurd support
[official-gcc.git] / libgo / go / os / user / getgrouplist_unix.go
blobe97e0bc64f608e67c4f3f0660493b1cfc48068c9
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build (dragonfly || freebsd || hurd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo
7 package user
9 import (
10 "fmt"
11 "syscall"
14 //extern-sysinfo getgrouplist
15 func getGroupList(name *byte, userGID syscall.Gid_t, gids *syscall.Gid_t, n *int32) int32
17 // groupRetry retries getGroupList with much larger size for n. The result is
18 // stored in gids.
19 func groupRetry(username string, name []byte, userGID syscall.Gid_t, gids *[]syscall.Gid_t, n *int32) error {
20 // More than initial buffer, but now n contains the correct size.
21 if *n > maxGroups {
22 return fmt.Errorf("user: %q is a member of more than %d groups", username, maxGroups)
24 *gids = make([]syscall.Gid_t, *n)
25 rv := getGroupList(&name[0], userGID, &(*gids)[0], n)
26 if rv == -1 {
27 return fmt.Errorf("user: list groups for %s failed", username)
29 return nil