"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 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: |
Rob Landley | 06ec8cf | 2006-03-03 19:02:50 +0000 | [diff] [blame] | 15 | * Move to dynamic allocation of (currently statically allocated) |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 16 | * buffers; especially for the group-related functions since |
| 17 | * large group member lists will cause error returns. |
| 18 | * |
| 19 | */ |
| 20 | |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 21 | #ifndef GETXXKEY_R_FUNC |
| 22 | #error GETXXKEY_R_FUNC is not defined! |
| 23 | #endif |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 24 | |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 25 | int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key, |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 26 | GETXXKEY_R_ENTTYPE *__restrict resultbuf, |
| 27 | char *__restrict buffer, size_t buflen, |
| 28 | GETXXKEY_R_ENTTYPE **__restrict result) |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 29 | { |
| 30 | FILE *stream; |
| 31 | int rv; |
| 32 | |
| 33 | *result = NULL; |
| 34 | |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 35 | stream = fopen_for_read(GETXXKEY_R_PATHNAME); |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 36 | if (!stream) |
| 37 | return errno; |
| 38 | while (1) { |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 39 | rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream); |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 40 | if (!rv) { |
| 41 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ |
| 42 | *result = resultbuf; |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 43 | break; |
| 44 | } |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 45 | } else { |
| 46 | if (rv == ENOENT) { /* end-of-file encountered. */ |
| 47 | rv = 0; |
| 48 | } |
| 49 | break; |
| 50 | } |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 51 | } |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 52 | fclose(stream); |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 53 | |
| 54 | return rv; |
| 55 | } |
| 56 | |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 57 | #undef GETXXKEY_R_FUNC |
| 58 | #undef GETXXKEY_R_PARSER |
| 59 | #undef GETXXKEY_R_ENTTYPE |
| 60 | #undef GETXXKEY_R_TEST |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 61 | #undef GETXXKEY_R_KEYTYPE |
| 62 | #undef GETXXKEY_R_PATHNAME |