1: static char *sccsid = "@(#)getpwent.c 4.1 10/9/80";
2:
3: #include <pwd.h>
4:
5: #undef BUFSIZ
6: #define BUFSIZ 160
7:
8: static int pwf = -1;
9: static char line[BUFSIZ+1];
10: static struct passwd passwd;
11:
12: setpwent()
13: {
14: if( pwf == -1 )
15: pwf = open( "/etc/passwd", 0 );
16: else
17: lseek(pwf, 0l, 0);
18: }
19:
20: endpwent()
21: {
22: if( pwf != -1 ){
23: close( pwf );
24: pwf = -1;
25: }
26: }
27:
28: static char *
29: pwskip(p)
30: register char *p;
31: {
32: while( *p && *p != ':' )
33: ++p;
34: if( *p ) *p++ = 0;
35: return(p);
36: }
37:
38: struct passwd *
39: getpwent()
40: {
41: register char *p, *q;
42: register int i, j;
43:
44: if (pwf == -1) {
45: if( (pwf = open( "/etc/passwd", 0 )) == -1 )
46: return(0);
47: }
48: i = read(pwf, line, BUFSIZ);
49: for (j = 0; j < i; j++)
50: if (line[j] == '\n')
51: break;
52: if (j >= i)
53: return(0);
54: line[++j] = 0;
55: lseek(pwf, (long) (j - i), 1);
56: p = line;
57: passwd.pw_name = p;
58: p = pwskip(p);
59: /* passwd.pw_passwd = p; */
60: p = q = pwskip(p);
61: /* passwd.pw_uid = atoi(p); */
62: p = pwskip(p);
63: p[-1] = 0;
64: passwd.pw_uid = atou(q);
65: /* passwd.pw_gid = atoi(p); */
66: /* passwd.pw_quota = 0; */
67: /* passwd.pw_comment = ""; */
68: q = p;
69: p = pwskip(p);
70: p[-1] = 0;
71: passwd.pw_gid = atou(q);
72: /* passwd.pw_gecos = p; */
73: p = pwskip(p);
74: passwd.pw_dir = p;
75: p = pwskip(p);
76: /* passwd.pw_shell = p; */
77: /* while(*p && *p != '\n') p++; */
78: *p = '\0';
79: return(&passwd);
80: }
81:
82: atou(p)
83: register char *p;
84: {
85: register int i = 0;
86:
87: if (p != 0)
88: while (*p)
89: i = i * 10 + *p++ - '0';
90: return (i);
91: }
Defined functions
atou
defined in line
82; used 2 times
Defined variables
line
defined in line
9; used 4 times
pwf
defined in line
8; used 10 times
sccsid
defined in line
1;
never used
Defined macros
BUFSIZ
defined in line
6; used 3 times