File: pwcache.c

package info (click to toggle)
procps 1%3A1.2.7-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 932 kB
  • ctags: 1,837
  • sloc: ansic: 7,984; makefile: 1,384; sh: 21
file content (37 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include "proc/ps.h"

#define	HASHSIZE	16			/* power of 2 */
#define	HASH(x)		((x) & (HASHSIZE - 1))


static struct pwbuf {
    int uid;
    char name[12];
    struct pwbuf *next;
} *pwhash[HASHSIZE];

char *user_from_uid(int uid)
{
    struct pwbuf **p;
    struct passwd *pw;

    p = &pwhash[HASH(uid)];
    while (*p) {
	if ((*p)->uid == uid)
	    return((*p)->name);
	p = &(*p)->next;
    }
    *p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
    (*p)->uid = uid;
    if ((pw = getpwuid(uid)) == NULL)
	sprintf((*p)->name, "#%d", uid);
    else
	sprintf((*p)->name, "%-.8s", pw->pw_name);
    (*p)->next = NULL;
    return((*p)->name);
}

void bad_user_access_length() { }