113650Ssam #ifndef lint 2*13706Ssam static char sccsid[] = "@(#)getpw.c 5.2 (Berkeley) 07/02/83"; 313650Ssam #endif 413650Ssam 5*13706Ssam #include <stdio.h> 613650Ssam getpw(uid,buf)713650Ssamgetpw(uid, buf) 813650Ssam int uid; 913650Ssam char buf[]; 1013650Ssam { 1113650Ssam static FILE *pwf; 1213650Ssam register n, c; 1313650Ssam register char *bp; 1413650Ssam 1513650Ssam if(pwf == 0) 1613650Ssam pwf = fopen("/etc/passwd", "r"); 1713650Ssam if(pwf == NULL) 1813650Ssam return(1); 1913650Ssam rewind(pwf); 2013650Ssam uid &= 0377; 2113650Ssam 2213650Ssam for (;;) { 2313650Ssam bp = buf; 2413650Ssam while((c=getc(pwf)) != '\n') { 2513650Ssam if(c <= 0) 2613650Ssam return(1); 2713650Ssam *bp++ = c; 2813650Ssam } 2913650Ssam *bp++ = '\0'; 3013650Ssam bp = buf; 3113650Ssam n = 3; 3213650Ssam while(--n) 3313650Ssam while((c = *bp++) != ':') 3413650Ssam if(c == '\n') 3513650Ssam return(1); 3613650Ssam while((c = *bp++) != ':') { 3713650Ssam if(c<'0' || c>'9') 3813650Ssam continue; 3913650Ssam n = n*10+c-'0'; 4013650Ssam } 4113650Ssam if(n == uid) 4213650Ssam return(0); 4313650Ssam } 4413650Ssam } 45