From 24396dae6795de77ba305f8c8798d681e3359962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aram=20H=C4=83v=C4=83rneanu?= Date: Mon, 30 Mar 2015 23:06:06 +0200 Subject: [PATCH] os/user: small fixes for Solaris Change-Id: I56149ef6607fb4d9baff9047cb3a47d71cad6fa6 Reviewed-on: https://go-review.googlesource.com/8261 Reviewed-by: Minux Ma --- src/os/user/lookup_unix.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/os/user/lookup_unix.go b/src/os/user/lookup_unix.go index 0871473df1d..f4f603ea871 100644 --- a/src/os/user/lookup_unix.go +++ b/src/os/user/lookup_unix.go @@ -17,6 +17,7 @@ import ( ) /* +#cgo solaris CFLAGS: -D_POSIX_PTHREAD_SEMANTICS #include #include #include @@ -24,7 +25,12 @@ import ( static int mygetpwuid_r(int uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) { - return getpwuid_r(uid, pwd, buf, buflen, result); + return getpwuid_r(uid, pwd, buf, buflen, result); +} + +static int mygetpwnam_r(const char *name, struct passwd *pwd, + char *buf, size_t buflen, struct passwd **result) { + return getpwnam_r(name, pwd, buf, buflen, result); } */ import "C" @@ -67,7 +73,11 @@ func lookupUnix(uid int, username string, lookupByName bool) (*User, error) { if lookupByName { nameC := C.CString(username) defer C.free(unsafe.Pointer(nameC)) - rv = C.getpwnam_r(nameC, + // mygetpwnam_r is a wrapper around getpwnam_r to avoid + // passing a size_t to getpwnam_r, because for unknown + // reasons passing a size_t to getpwnam_r doesn't work on + // Solaris. + rv = C.mygetpwnam_r(nameC, &pwd, (*C.char)(buf), C.size_t(bufSize),