- register struct passwd *pw;
- static init;
- struct passwd *getpwent();
-
- if (uid >= 0 && uid < NUID && names[uid][0])
- return (&names[uid][0]);
- if (init == 2)
- return (0);
- if (init == 0)
- setpwent(), init = 1;
- while (pw = getpwent()) {
- if (pw->pw_uid >= NUID)
- continue;
- if (names[pw->pw_uid][0])
- continue;
- (void) strncpy(names[pw->pw_uid], pw->pw_name, NMAX);
- if (pw->pw_uid == uid)
- return (&names[uid][0]);
+ register struct passwd *pw;
+ static init = 0;
+ struct passwd *getpwent();
+ register struct nametable *n;
+
+ /*
+ * find uid in hashed table; add it if not found.
+ * return pointer to name.
+ */
+
+ if ((n = findslot(uid)) == NULL)
+ return((char *)NULL);
+
+ if (n->nt_name[0]) /* occupied? */
+ return(n->nt_name);
+
+ switch (init) {
+ case 0:
+ setpwent();
+ init = 1;
+ /* intentional fall-thru */
+ case 1:
+ while (pw = getpwent()) {
+ if (pw->pw_uid < 0)
+ continue;
+ if ((n = findslot(pw->pw_uid)) == NULL) {
+ endpwent();
+ init = 2;
+ return((char *)NULL);
+ }
+ if (n->nt_name[0])
+ continue; /* duplicate, not uid */
+ strncpy(n->nt_name, pw->pw_name, NMAX);
+ n->nt_uid = pw->pw_uid;
+ if (pw->pw_uid == uid)
+ return (n->nt_name);
+ }
+ endpwent();
+ init = 2;
+ /* intentional fall-thru */
+ case 2:
+ return ((char *)NULL);