]> Cypherpunks repositories - gostls13.git/commitdiff
os/user: don't create C function mygetgrouplist
authorIan Lance Taylor <iant@golang.org>
Tue, 10 May 2016 21:27:32 +0000 (14:27 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 10 May 2016 22:32:38 +0000 (22:32 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/user/getgrouplist_darwin.go [moved from src/os/user/getgrouplist_darwin.c with 64% similarity]
src/os/user/getgrouplist_unix.go [moved from src/os/user/getgrouplist_unix.c with 56% similarity]
src/os/user/listgroups_unix.go

similarity index 64%
rename from src/os/user/getgrouplist_darwin.c
rename to src/os/user/getgrouplist_darwin.go
index 6ad561489829ea682e4c9cb63b1f7e5863308050..54a2da3610434c0ec64e2dcf547340b1a675fe85 100644 (file)
@@ -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 <unistd.h>
 #include <sys/types.h>
 #include <stdlib.h>
 
-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)
+}
similarity index 56%
rename from src/os/user/getgrouplist_unix.c
rename to src/os/user/getgrouplist_unix.go
index eb14f9ab8a0ac176ec81434c2d85e46d7f3861f2..14da7c00a2b55de0319b6a790fdf243f6b4b88b9 100644 (file)
@@ -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 <unistd.h>
 #include <sys/types.h>
 #include <grp.h>
 
-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)
+}
index f78baaac1e27f7153c3025c7ddf1dc469cf2cfb9..db952c64bffdb3b76be729aebf71b60a785c2fb4 100644 (file)
@@ -16,8 +16,6 @@ import (
 #include <unistd.h>
 #include <sys/types.h>
 #include <stdlib.h>
-
-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)
                }