]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/libg/gtunum.c
Replaced use of snprintf() with memcpy()/memmove().
[nmh] / docs / historical / mh-jun-1982 / Extras / libg / gtunum.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "libg.h"
9
10 getunum(name)
11 char *name;
12 {
13 register char *bp, *np;
14 register c;
15 int inptr[259];
16 int uid;
17
18 if (pich <= 0)
19 pich = open("/etc/passwd",0);
20 if (pich < 0) return(-1);
21 seek(pich,0,0);
22 inptr[0] = pich;
23 inptr[1] = inptr[2] = 0;
24 uid = 0;
25 if (u_buf[0] != 0) goto test; /* first test what is presently in
26 the buffer */
27
28 for(;;) {
29
30 bp = u_buf;
31 while((c=getc(inptr)) != '\n') {
32 if (c <= 0) return(-1);
33 *bp++ = c;
34 }
35 *bp++ = '\0';
36
37 test: bp = u_buf;
38 np = name;
39 while(*bp++ == *np++);
40 --bp; --np;
41 if (*bp++ == ':' &&
42 *np++ == '\0') {
43 while(*bp++ != ':');
44 while(*bp != ':')
45 uid = uid * 10 + *bp++ - '0';
46 last_uid = uid;
47 return(uid);
48 }
49 }
50 return(-1);
51 }