Add copyright
[unix-history] / usr / src / lib / libcompat / 4.1 / getpw.c
CommitLineData
bb0cfa24
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8static char sccsid[] = "@(#)getpw.c 5.1 (Berkeley) %G%";
9#endif not lint
10
0a237a55
BJ
11#include <stdio.h>
12
13getpw(uid, buf)
14int uid;
15char buf[];
16{
17 static FILE *pwf;
18 register n, c;
19 register char *bp;
20
21 if(pwf == 0)
22 pwf = fopen("/etc/passwd", "r");
23 if(pwf == NULL)
24 return(1);
25 rewind(pwf);
26
27 for (;;) {
28 bp = buf;
29 while((c=getc(pwf)) != '\n') {
30 if(c == EOF)
31 return(1);
32 *bp++ = c;
33 }
34 *bp++ = '\0';
35 bp = buf;
36 n = 3;
37 while(--n)
38 while((c = *bp++) != ':')
39 if(c == '\n')
40 return(1);
41 while((c = *bp++) != ':') {
42 if(c<'0' || c>'9')
43 continue;
44 n = n*10+c-'0';
45 }
46 if(n == uid)
47 return(0);
48 }
49}