blob: ffdc85e4ee6108ad709db5c37cd7ec9a246f481a [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +00002/* 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:
Rob Landley06ec8cf2006-03-03 19:02:50 +000015 * Move to dynamic allocation of (currently statically allocated)
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000016 * buffers; especially for the group-related functions since
17 * large group member lists will cause error returns.
18 *
19 */
20
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000021#ifndef GETXXKEY_R_FUNC
22#error GETXXKEY_R_FUNC is not defined!
23#endif
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000024
Denis Vlasenkocb04ff52006-12-30 21:11:57 +000025int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000026 GETXXKEY_R_ENTTYPE *__restrict resultbuf,
27 char *__restrict buffer, size_t buflen,
28 GETXXKEY_R_ENTTYPE **__restrict result)
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000029{
30 FILE *stream;
31 int rv;
32
33 *result = NULL;
34
Denis Vlasenko5415c852008-07-21 23:05:26 +000035 stream = fopen_for_read(GETXXKEY_R_PATHNAME);
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000036 if (!stream)
37 return errno;
38 while (1) {
Denis Vlasenkocb04ff52006-12-30 21:11:57 +000039 rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000040 if (!rv) {
41 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
42 *result = resultbuf;
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000043 break;
44 }
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000045 } else {
46 if (rv == ENOENT) { /* end-of-file encountered. */
47 rv = 0;
48 }
49 break;
50 }
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000051 }
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000052 fclose(stream);
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000053
54 return rv;
55}
56
Bernhard Reutner-Fischer30c7de02005-10-28 11:21:40 +000057#undef GETXXKEY_R_FUNC
58#undef GETXXKEY_R_PARSER
59#undef GETXXKEY_R_ENTTYPE
60#undef GETXXKEY_R_TEST
Denis Vlasenkocb04ff52006-12-30 21:11:57 +000061#undef GETXXKEY_R_KEYTYPE
62#undef GETXXKEY_R_PATHNAME