github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/src/os/user/getgrouplist_darwin.c (about)

     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.
     4  
     5  // +build cgo
     6  
     7  #include <unistd.h>
     8  #include <sys/types.h>
     9  #include <stdlib.h>
    10  
    11  int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) {
    12  	int* buf = malloc(*ngroups * sizeof(int));
    13  	int rv = getgrouplist(user, (int) group, buf, ngroups);
    14  	int i;
    15  	if (rv == 0) {
    16  		for (i = 0; i < *ngroups; i++) {
    17  			groups[i] = (gid_t) buf[i];
    18  		}
    19  	}
    20  	free(buf);
    21  	return rv;
    22  }