# HG changeset patch # User Jim Meyering # Date 868197029 0 # Node ID 029c8dd12d60df413f6a4410dd9d91d1936c7baf # Parent 2db1c866ccce4d7da2a943df597b7b2cf74ec3b9 (getuser): Return NULL (rather than stringified uid) upon lookup failure. (getgroup): Likewise. (getuidbyname) [NOT_USED]: #ifdef-out unused function. (getgidbyname) [NOT_USED]: #ifdef-out unused function. diff --git a/lib/idcache.c b/lib/idcache.c --- a/lib/idcache.c +++ b/lib/idcache.c @@ -1,5 +1,5 @@ /* idcache.c -- map user and group IDs, cached for speed - Copyright (C) 1985, 1988, 1989, 1990 Free Software Foundation, Inc. + Copyright (C) 1985, 1988, 1989, 1990, 1997 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,8 +15,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include +#if HAVE_CONFIG_H +# include #endif #include @@ -25,14 +25,15 @@ #include #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) -#include +# include #else -#include +# include #endif -#ifdef HAVE_UNISTD_H -#include +#if HAVE_UNISTD_H +# include #endif + #ifndef _POSIX_VERSION struct passwd *getpwuid (); struct passwd *getpwnam (); @@ -56,11 +57,14 @@ static struct userid *user_alist; +#ifdef NOT_USED /* The members of this list have names not in the local passwd file. */ static struct userid *nouser_alist; +#endif /* NOT_USED */ -/* Translate UID to a login name or a stringified number, - with cache. */ +/* Translate UID to a login name, with cache. + If UID cannot be resolved, return NULL. + Cache lookup failures, too. */ char * getuser (uid) @@ -68,7 +72,6 @@ { register struct userid *tail; struct passwd *pwent; - char usernum_string[20]; for (tail = user_alist; tail; tail = tail->next) if (tail->id.u == uid) @@ -77,13 +80,7 @@ pwent = getpwuid (uid); tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->id.u = uid; - if (pwent == 0) - { - sprintf (usernum_string, "%u", (unsigned) uid); - tail->name = xstrdup (usernum_string); - } - else - tail->name = xstrdup (pwent->pw_name); + tail->name = (pwent ? xstrdup (pwent->pw_name) : NULL); /* Add to the head of the list, so most recently used is first. */ tail->next = user_alist; @@ -91,6 +88,8 @@ return tail->name; } +#ifdef NOT_USED + /* Translate USER to a UID, with cache. Return NULL if there is no such user. (We also cache which user names have no passwd entry, @@ -132,6 +131,8 @@ return 0; } +#endif /* NOT_USED */ + /* Use the same struct as for userids. */ static struct userid *group_alist; static struct userid *nogroup_alist; @@ -145,7 +146,6 @@ { register struct userid *tail; struct group *grent; - char groupnum_string[20]; for (tail = group_alist; tail; tail = tail->next) if (tail->id.g == gid) @@ -154,13 +154,7 @@ grent = getgrgid (gid); tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->id.g = gid; - if (grent == 0) - { - sprintf (groupnum_string, "%u", (unsigned int) gid); - tail->name = xstrdup (groupnum_string); - } - else - tail->name = xstrdup (grent->gr_name); + tail->name = (grent ? xstrdup (grent->gr_name) : NULL); /* Add to the head of the list, so most recently used is first. */ tail->next = group_alist; @@ -168,7 +162,9 @@ return tail->name; } -/* Translate GROUP to a UID, with cache. +#ifdef NOT_USED + +/* Translate GROUP to a GID, with cache. Return NULL if there is no such group. (We also cache which group names have no group entry, so we don't keep looking them up.) */ @@ -208,3 +204,5 @@ nogroup_alist = tail; return 0; } + +#endif /* NOT_USED */