* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)pwcache.c 5.4 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#define NCACHE 64 /* power of 2 */
#define MASK NCACHE - 1 /* bits to store with */
user_from_uid(uid
, nouser
)
char name
[UT_NAMESIZE
+ 1];
static char nbuf
[15]; /* 32 bits == 10 digits */
register struct passwd
*pw
;
register struct ncache
*cp
;
cp
= c_uid
+ (uid
& MASK
);
if (cp
->uid
!= uid
|| !*cp
->name
) {
if (!(pw
= getpwuid(uid
))) {
(void)sprintf(nbuf
, "%u", uid
);
(void)strncpy(cp
->name
, pw
->pw_name
, UT_NAMESIZE
);
cp
->name
[UT_NAMESIZE
] = '\0';
group_from_gid(gid
, nogroup
)
static char nbuf
[15]; /* 32 bits == 10 digits */
register struct group
*gr
;
register struct ncache
*cp
;
cp
= c_gid
+ (gid
& MASK
);
if (cp
->gid
!= gid
|| !*cp
->name
) {
if (!(gr
= getgrgid(gid
))) {
(void)sprintf(nbuf
, "%u", gid
);
(void)strncpy(cp
->name
, gr
->gr_name
, UT_NAMESIZE
);
cp
->name
[UT_NAMESIZE
] = '\0';