"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 2 | /* Copyright (C) 2003 Manuel Novoa III |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 3 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 4 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | /* Nov 6, 2003 Initial version. |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 8 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 9 | * NOTE: This implementation is quite strict about requiring all |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 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 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 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. |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 20 | #ifndef GETXXKEY_R_FUNC |
| 21 | #error GETXXKEY_R_FUNC is not defined! |
| 22 | #endif |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 23 | |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 24 | int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key, |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 25 | GETXXKEY_R_ENTTYPE *__restrict resultbuf, |
| 26 | char *__restrict buffer, size_t buflen, |
| 27 | GETXXKEY_R_ENTTYPE **__restrict result) |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 28 | { |
| 29 | FILE *stream; |
| 30 | int rv; |
| 31 | |
| 32 | *result = NULL; |
| 33 | |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 34 | stream = fopen_for_read(GETXXKEY_R_PATHNAME); |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 35 | if (!stream) |
| 36 | return errno; |
| 37 | while (1) { |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 38 | rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream); |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 39 | if (!rv) { |
| 40 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ |
| 41 | *result = resultbuf; |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 42 | break; |
| 43 | } |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 44 | } else { |
| 45 | if (rv == ENOENT) { /* end-of-file encountered. */ |
| 46 | rv = 0; |
| 47 | } |
| 48 | break; |
| 49 | } |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 50 | } |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 51 | fclose(stream); |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 52 | |
| 53 | return rv; |
| 54 | } |
| 55 | |
Bernhard Reutner-Fischer | 30c7de0 | 2005-10-28 11:21:40 +0000 | [diff] [blame] | 56 | #undef GETXXKEY_R_FUNC |
| 57 | #undef GETXXKEY_R_PARSER |
| 58 | #undef GETXXKEY_R_ENTTYPE |
| 59 | #undef GETXXKEY_R_TEST |
Denis Vlasenko | cb04ff5 | 2006-12-30 21:11:57 +0000 | [diff] [blame] | 60 | #undef GETXXKEY_R_KEYTYPE |
| 61 | #undef GETXXKEY_R_PATHNAME |