1 | /* vi: set sw=4 ts=4: */
|
---|
2 | /* Copyright (C) 2003 Manuel Novoa III
|
---|
3 | *
|
---|
4 | * Licensed under GPL v2, or later. See file LICENSE in this tarball.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /* Nov 6, 2003 Initial version.
|
---|
8 | *
|
---|
9 | * NOTE: This implementation is quite strict about requiring all
|
---|
10 | * field seperators. It also does not allow leading whitespace
|
---|
11 | * except when processing the numeric fields. glibc is more
|
---|
12 | * lenient. See the various glibc difference comments below.
|
---|
13 | *
|
---|
14 | * TODO:
|
---|
15 | * Move to dynamic allocation of (currently statically allocated)
|
---|
16 | * buffers; especially for the group-related functions since
|
---|
17 | * large group member lists will cause error returns.
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef GETXXKEY_R_FUNC
|
---|
22 | #error GETXXKEY_R_FUNC is not defined!
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
|
---|
26 | GETXXKEY_R_ENTTYPE *__restrict resultbuf,
|
---|
27 | char *__restrict buffer, size_t buflen,
|
---|
28 | GETXXKEY_R_ENTTYPE **__restrict result)
|
---|
29 | {
|
---|
30 | FILE *stream;
|
---|
31 | int rv;
|
---|
32 |
|
---|
33 | *result = NULL;
|
---|
34 |
|
---|
35 | stream = fopen(GETXXKEY_R_PATHNAME, "r");
|
---|
36 | if (!stream)
|
---|
37 | return errno;
|
---|
38 | while (1) {
|
---|
39 | rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
|
---|
40 | if (!rv) {
|
---|
41 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
|
---|
42 | *result = resultbuf;
|
---|
43 | break;
|
---|
44 | }
|
---|
45 | } else {
|
---|
46 | if (rv == ENOENT) { /* end-of-file encountered. */
|
---|
47 | rv = 0;
|
---|
48 | }
|
---|
49 | break;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | fclose(stream);
|
---|
53 |
|
---|
54 | return rv;
|
---|
55 | }
|
---|
56 |
|
---|
57 | #undef GETXXKEY_R_FUNC
|
---|
58 | #undef GETXXKEY_R_PARSER
|
---|
59 | #undef GETXXKEY_R_ENTTYPE
|
---|
60 | #undef GETXXKEY_R_TEST
|
---|
61 | #undef GETXXKEY_R_KEYTYPE
|
---|
62 | #undef GETXXKEY_R_PATHNAME
|
---|