From e11c7df86144bed383ac6bbeaecc3017d18b37db Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Mon, 11 Jan 1999 10:55:18 +0000 Subject: beta: rc-1.5b4 --- which.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'which.c') diff --git a/which.c b/which.c index 372cc92..9a6e1bb 100644 --- a/which.c +++ b/which.c @@ -9,18 +9,17 @@ */ #include "rc.h" + #include -#include #include -#include + +#include "getgroups.h" #define X_USR 0100 #define X_GRP 0010 #define X_OTH 0001 #define X_ALL (X_USR|X_GRP|X_OTH) -extern int stat(const char *, struct stat *); - static bool initialized = FALSE; static uid_t uid; static gid_t gid; @@ -32,7 +31,7 @@ static GETGROUPS_T *gidset; /* determine whether gid lies in gidset */ static int ingidset(gid_t g) { - gid_t i; + int i; for (i = 0; i < ngroups; ++i) if (g == gidset[i]) return 1; @@ -87,12 +86,17 @@ extern char *which(char *name, bool verbose) { uid = geteuid(); gid = getegid(); #if HAVE_GETGROUPS - ngroups = getgroups(0, (gid_t *)0); - gidset = malloc(ngroups * sizeof(gid_t)); - if (!gidset) - uerror("malloc"); - else - getgroups(ngroups, gidset); +#if HAVE_POSIX_GETGROUPS + ngroups = getgroups(0, (GETGROUPS_T *)0); + if (ngroups < 0) { + uerror("getgroups"); + rc_exit(1); + } +#else + ngroups = NGROUPS; +#endif + gidset = ealloc(ngroups * sizeof(GETGROUPS_T)); + getgroups(ngroups, gidset); #endif } if (isabsolute(name)) /* absolute pathname? */ -- cgit v1.2.3