version 1.16, 2009/11/11 23:49:01 |
version 1.17, 2011/07/04 21:34:54 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <limits.h> |
#include <limits.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
int myfd, eof, foundit; |
int myfd, eof, foundit; |
char *record, *s; |
char *record, *s; |
int tc_not_resolved; |
int tc_not_resolved; |
|
|
/* |
/* |
* Return with ``loop detected'' error if we've recursed more than |
* Return with ``loop detected'' error if we've recursed more than |
* MAX_RECURSION times. |
* MAX_RECURSION times. |
|
|
for (;;) { |
for (;;) { |
if (bp >= b_end) { |
if (bp >= b_end) { |
int n; |
int n; |
|
|
n = read(fd, buf, sizeof(buf)); |
n = read(fd, buf, sizeof(buf)); |
if (n <= 0) { |
if (n <= 0) { |
if (myfd) |
if (myfd) |
|
|
b_end = buf+n; |
b_end = buf+n; |
bp = buf; |
bp = buf; |
} |
} |
|
|
c = *bp++; |
c = *bp++; |
if (c == '\n') { |
if (c == '\n') { |
if (bp >= b_end) { |
if (bp >= b_end) { |
|
|
*rp++ = c; |
*rp++ = c; |
|
|
/* |
/* |
* Enforce loop invariant: if no room |
* Enforce loop invariant: if no room |
* left in record buffer, try to get |
* left in record buffer, try to get |
* some more. |
* some more. |
*/ |
*/ |
|
|
} |
} |
/* loop invariant lets us do this */ |
/* loop invariant lets us do this */ |
*rp++ = '\0'; |
*rp++ = '\0'; |
|
|
/* |
/* |
* Toss blank lines and comments. |
* Toss blank lines and comments. |
*/ |
*/ |
if (*record == '\0' || *record == '#') |
if (*record == '\0' || *record == '#') |
continue; |
continue; |
|
|
/* |
/* |
* See if this is the record we want ... |
* See if this is the record we want ... |
*/ |
*/ |
|
|
tc_not_resolved = 1; |
tc_not_resolved = 1; |
/* couldn't resolve tc */ |
/* couldn't resolve tc */ |
if (iret == -1) { |
if (iret == -1) { |
*(s - 1) = ','; |
*(s - 1) = ','; |
scan = s - 1; |
scan = s - 1; |
tc_not_resolved = 1; |
tc_not_resolved = 1; |
continue; |
continue; |
|
|
} |
} |
} |
} |
/* not interested in name field of tc'ed record */ |
/* not interested in name field of tc'ed record */ |
|
|
*/ |
*/ |
scan = s-1; |
scan = s-1; |
} |
} |
|
|
} |
} |
/* |
/* |
* Close file (if we opened it), give back any extra memory, and |
* Close file (if we opened it), give back any extra memory, and |
|
|
(void)close(fd); |
(void)close(fd); |
*len = rp - record - 1; /* don't count NUL */ |
*len = rp - record - 1; /* don't count NUL */ |
if (r_end > rp) { |
if (r_end > rp) { |
if ((s = |
if ((s = |
realloc(record, (size_t)(rp - record))) == NULL) { |
realloc(record, (size_t)(rp - record))) == NULL) { |
free(record); |
free(record); |
errno = ENOMEM; |
errno = ENOMEM; |
|
|
} else |
} else |
record = s; |
record = s; |
} |
} |
|
|
*cap = record; |
*cap = record; |
if (tc_not_resolved) |
if (tc_not_resolved) |
return (1); |
return (1); |
return (0); |
return (0); |
} |
} |
|
|
/* |
/* |
* Igetmatch will return 0 if name is one of the names of the capability |
* Igetmatch will return 0 if name is one of the names of the capability |
|
|
} |
} |
|
|
/* |
/* |
* Igetnext() gets either the first or next entry in the logical database |
* Igetnext() gets either the first or next entry in the logical database |
* specified by db_array. It returns 0 upon completion of the database, 1 |
* specified by db_array. It returns 0 upon completion of the database, 1 |
* upon returning an entry with more remaining, and -1 if an error occurs. |
* upon returning an entry with more remaining, and -1 if an error occurs. |
*/ |
*/ |
|
|
else |
else |
slash = 0; |
slash = 0; |
|
|
/* |
/* |
* Line points to a name line. |
* Line points to a name line. |
*/ |
*/ |
done = 0; |
done = 0; |