From a4dbe92a7558c1724e8affcfe8f5490cf8eb6ffe Mon Sep 17 00:00:00 2001 From: dg Date: Tue, 5 Mar 1996 13:11:42 +0000 Subject: Implemented negative caching on uid/gid lookup failures. This won't matter much on some systems, but on ftp servers (like wcarchive) where you run with special stripped group and pwd.db files in the anonymous ftp /etc, this can be a major speedup for ls(1). --- lib/libc/gen/pwcache.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c index 7c266c1..05773bd 100644 --- a/lib/libc/gen/pwcache.c +++ b/lib/libc/gen/pwcache.c @@ -53,10 +53,10 @@ user_from_uid(uid, nouser) { static struct ncache { uid_t uid; + int found; char name[UT_NAMESIZE + 1]; } c_uid[NCACHE]; static int pwopen; - static char nbuf[15]; /* 32 bits == 10 digits */ register struct passwd *pw; register struct ncache *cp; @@ -66,15 +66,18 @@ user_from_uid(uid, nouser) setpassent(1); pwopen = 1; } - if ((pw = getpwuid(uid)) == NULL) { + pw = getpwuid(uid); + cp->uid = uid; + if (pw != NULL) { + cp->found = 1; + (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid); if (nouser) return (NULL); - (void)snprintf(nbuf, sizeof(nbuf), "%u", uid); - return (nbuf); } - cp->uid = uid; - (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } @@ -86,10 +89,10 @@ group_from_gid(gid, nogroup) { static struct ncache { gid_t gid; + int found; char name[UT_NAMESIZE + 1]; } c_gid[NCACHE]; static int gropen; - static char nbuf[15]; /* 32 bits == 10 digits */ struct group *gr; struct ncache *cp; @@ -99,15 +102,18 @@ group_from_gid(gid, nogroup) setgroupent(1); gropen = 1; } - if ((gr = getgrgid(gid)) == NULL) { + gr = getgrgid(gid); + cp->gid = gid; + if (gr != NULL) { + cp->found = 1; + (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid); if (nogroup) return (NULL); - (void)snprintf(nbuf, sizeof(nbuf), "%u", gid); - return (nbuf); } - cp->gid = gid; - (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } -- cgit v1.1