fixes from rick adams
[unix-history] / usr / src / usr.bin / uucp / port / getpw.c
CommitLineData
8c91aff0 1#ifndef lint
62ba4a08 2static char sccsid[] = "@(#)getpw.c 5.2 (Berkeley) %G%";
8c91aff0
SL
3#endif
4
62ba4a08 5#include <stdio.h>
8c91aff0
SL
6
7getpw(uid, buf)
8int uid;
9char buf[];
10{
11 static FILE *pwf;
12 register n, c;
13 register char *bp;
14
15 if(pwf == 0)
16 pwf = fopen("/etc/passwd", "r");
17 if(pwf == NULL)
18 return(1);
19 rewind(pwf);
20 uid &= 0377;
21
22 for (;;) {
23 bp = buf;
24 while((c=getc(pwf)) != '\n') {
25 if(c <= 0)
26 return(1);
27 *bp++ = c;
28 }
29 *bp++ = '\0';
30 bp = buf;
31 n = 3;
32 while(--n)
33 while((c = *bp++) != ':')
34 if(c == '\n')
35 return(1);
36 while((c = *bp++) != ':') {
37 if(c<'0' || c>'9')
38 continue;
39 n = n*10+c-'0';
40 }
41 if(n == uid)
42 return(0);
43 }
44}