From: Ian Lance Taylor Date: Tue, 10 May 2016 21:27:32 +0000 (-0700) Subject: os/user: don't create C function mygetgrouplist X-Git-Tag: go1.7beta1~257 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9780bf2a9587b6aa0c92526cc1d6d6d1ed4c7210;p=gostls13.git os/user: don't create C function mygetgrouplist Instead of exporting the C function mygetgrouplist as a global symbol to conflict with other symbols of the same name, use trivial Go code and a static C function. Change-Id: I98dd667814d0a0ed8f7b1d4cfc6483d5a6965b26 Reviewed-on: https://go-review.googlesource.com/23008 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/os/user/getgrouplist_darwin.c b/src/os/user/getgrouplist_darwin.go similarity index 64% rename from src/os/user/getgrouplist_darwin.c rename to src/os/user/getgrouplist_darwin.go index 6ad5614898..54a2da3610 100644 --- a/src/os/user/getgrouplist_darwin.c +++ b/src/os/user/getgrouplist_darwin.go @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build cgo +package user +/* #include #include #include -int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { +static int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { int* buf = malloc(*ngroups * sizeof(int)); int rv = getgrouplist(user, (int) group, buf, ngroups); int i; @@ -20,3 +21,9 @@ int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { free(buf); return rv; } +*/ +import "C" + +func getGroupList(name *C.char, userGID C.gid_t, gids *C.gid_t, n *C.int) C.int { + return C.mygetgrouplist(name, userGID, gids, n) +} diff --git a/src/os/user/getgrouplist_unix.c b/src/os/user/getgrouplist_unix.go similarity index 56% rename from src/os/user/getgrouplist_unix.c rename to src/os/user/getgrouplist_unix.go index eb14f9ab8a..14da7c00a2 100644 --- a/src/os/user/getgrouplist_unix.c +++ b/src/os/user/getgrouplist_unix.go @@ -2,13 +2,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build cgo // +build dragonfly freebsd !android,linux netbsd openbsd +package user + +/* #include #include #include -int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { +static int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { return getgrouplist(user, group, groups, ngroups); } +*/ +import "C" + +func getGroupList(name *C.char, userGID C.gid_t, gids *C.gid_t, n *C.int) C.int { + return C.mygetgrouplist(name, userGID, gids, n) +} diff --git a/src/os/user/listgroups_unix.go b/src/os/user/listgroups_unix.go index f78baaac1e..db952c64bf 100644 --- a/src/os/user/listgroups_unix.go +++ b/src/os/user/listgroups_unix.go @@ -16,8 +16,6 @@ import ( #include #include #include - -extern int mygetgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups); */ import "C" @@ -32,7 +30,7 @@ func listGroups(u *User) ([]string, error) { n := C.int(256) gidsC := make([]C.gid_t, n) - rv := C.mygetgrouplist(nameC, userGID, &gidsC[0], &n) + rv := getGroupList(nameC, userGID, &gidsC[0], &n) if rv == -1 { // More than initial buffer, but now n contains the correct size. const maxGroups = 2048 @@ -40,7 +38,7 @@ func listGroups(u *User) ([]string, error) { return nil, fmt.Errorf("user: list groups for %s: member of more than %d groups", u.Username, maxGroups) } gidsC = make([]C.gid_t, n) - rv := C.mygetgrouplist(nameC, userGID, &gidsC[0], &n) + rv := getGroupList(nameC, userGID, &gidsC[0], &n) if rv == -1 { return nil, fmt.Errorf("user: list groups for %s failed (changed groups?)", u.Username) }