1 // Copyright (C) 1992-1998 by Michael K. Johnson, johnsonm@redhat.com
2 // Note: most likely none of his code remains
4 // Copyright 2002, Albert Cahalan
6 // This file is placed under the conditions of the GNU Library
7 // General Public License, version 2, or any later version.
8 // See file COPYING for information on distribution conditions.
12 #include <sys/types.h>
19 // might as well fill cache lines... else we waste memory anyway
21 #define HASHSIZE 64 /* power of 2 */
22 #define HASH(x) ((x) & (HASHSIZE - 1))
30 char *user_from_uid(uid_t uid) {
34 p = &pwhash[HASH(uid)];
40 *p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
43 if(!pw || strlen(pw->pw_name) >= P_G_SZ)
44 sprintf((*p)->name, "%u", uid);
46 strcpy((*p)->name, pw->pw_name);
52 static struct grpbuf {
58 char *group_from_gid(gid_t gid) {
62 g = &grphash[HASH(gid)];
68 *g = (struct grpbuf *) malloc(sizeof(struct grpbuf));
71 if (!gr || strlen(gr->gr_name) >= P_G_SZ)
72 sprintf((*g)->name, "%u", gid);
74 strcpy((*g)->name, gr->gr_name);