Annotation of 43BSD/lib/libc/compat-4.1/getpw.c, revision 1.1.1.1

1.1       root        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: #if defined(LIBC_SCCS) && !defined(lint)
                      8: static char sccsid[] = "@(#)getpw.c    5.2 (Berkeley) 3/9/86";
                      9: #endif LIBC_SCCS and not lint
                     10: 
                     11: #include       <stdio.h>
                     12: 
                     13: getpw(uid, buf)
                     14: int uid;
                     15: char 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: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.