manual page distributed with 4.1BSD
[unix-history] / usr / src / lib / libcompat / 4.1 / getpw.c
CommitLineData
0a237a55
BJ
1/* @(#)getpw.c 4.1 (Berkeley) %G% */
2#include <stdio.h>
3
4getpw(uid, buf)
5int uid;
6char buf[];
7{
8 static FILE *pwf;
9 register n, c;
10 register char *bp;
11
12 if(pwf == 0)
13 pwf = fopen("/etc/passwd", "r");
14 if(pwf == NULL)
15 return(1);
16 rewind(pwf);
17
18 for (;;) {
19 bp = buf;
20 while((c=getc(pwf)) != '\n') {
21 if(c == EOF)
22 return(1);
23 *bp++ = c;
24 }
25 *bp++ = '\0';
26 bp = buf;
27 n = 3;
28 while(--n)
29 while((c = *bp++) != ':')
30 if(c == '\n')
31 return(1);
32 while((c = *bp++) != ':') {
33 if(c<'0' || c>'9')
34 continue;
35 n = n*10+c-'0';
36 }
37 if(n == uid)
38 return(0);
39 }
40}