Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / misc / getpw.c
1 /*
2  * getpw - get a password from the password file
3  */
4 /* $Id: getpw.c,v 1.2 1994/06/24 11:45:21 ceriel Exp $ */
5
6 #include        <stdio.h>
7
8 getpw(int uid, char buf[])
9 {
10         register FILE *pwf;
11         register int ch, i;
12         register char *bp;
13
14         pwf = fopen("/etc/passwd", "r");
15         if (pwf == NULL) return(1);
16
17         for (;;) {
18                 bp = buf;
19                 while ((ch = getc(pwf)) != '\n') {
20                         if (ch == EOF) return 1;
21                         *bp++ = ch;
22                 }
23                 *bp++ = '\0';
24                 bp = buf;
25                 for (i = 2; i; i--) {
26                         while ((ch = *bp++) != ':') {
27                                 if(ch = '\0') return 1;
28                         }
29                 }
30                 i = 0;
31                 while ((ch = *bp++) != ':') {
32                         if (ch < '0' || ch > '9') return 1;
33                         i = i * 10 + (ch - '0');
34                 }
35                 if (i == uid) return(0);
36         }
37         /*NOTREACHED*/
38 }