// Code generated by cmd/cgo; DO NOT EDIT.

//line /home/evie/packages/go/go-1.18-0/go/src/os/user/getgrouplist_unix.go:1:1
// Copyright 2016 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.

//go:build (dragonfly || freebsd || (!android && linux) || netbsd || openbsd || (solaris && !illumos)) && cgo && !osusergo

package user

/*
#include <unistd.h>
#include <sys/types.h>
#include <grp.h>

static int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
	return getgrouplist(user, group, groups, ngroups);
}
*/
import _ "unsafe"
import (
	"fmt"
	"unsafe"
)

func getGroupList(name * /*line :24:25*/_Ctype_char /*line :24:31*/, userGID  /*line :24:41*/_Ctype_gid_t /*line :24:48*/, gids * /*line :24:56*/_Ctype_gid_t /*line :24:63*/, n * /*line :24:68*/_Ctype_int /*line :24:73*/)  /*line :24:75*/_Ctype_int /*line :24:80*/ {
	return ( /*line :25:9*/_Cfunc_mygetgrouplist /*line :25:24*/)(name, userGID, gids, n)
}

// groupRetry retries getGroupList with much larger size for n. The result is
// stored in gids.
func groupRetry(username string, name []byte, userGID  /*line :30:55*/_Ctype_gid_t /*line :30:62*/, gids *[] /*line :30:72*/_Ctype_gid_t /*line :30:79*/, n * /*line :30:84*/_Ctype_int /*line :30:89*/) error {
	// More than initial buffer, but now n contains the correct size.
	if *n > maxGroups {
		return fmt.Errorf("user: %q is a member of more than %d groups", username, maxGroups)
	}
	*gids = make([] /*line :35:17*/_Ctype_gid_t /*line :35:24*/, *n)
	rv := getGroupList((* /*line :36:23*/_Ctype_char /*line :36:29*/)(unsafe.Pointer(&name[0])), userGID, &(*gids)[0], n)
	if rv == -1 {
		return fmt.Errorf("user: list groups for %s failed", username)
	}
	return nil
}
