2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2010-08-16 23:44:46 +05:30
|
|
|
/* Copyright (C) 2003 Manuel Novoa III
|
2005-10-28 16:51:40 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2005-10-28 16:51:40 +05:30
|
|
|
*/
|
|
|
|
|
2010-08-16 23:44:46 +05:30
|
|
|
/* Nov 6, 2003 Initial version.
|
2005-10-28 16:51:40 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* NOTE: This implementation is quite strict about requiring all
|
2005-10-28 16:51:40 +05:30
|
|
|
* field seperators. It also does not allow leading whitespace
|
|
|
|
* except when processing the numeric fields. glibc is more
|
|
|
|
* lenient. See the various glibc difference comments below.
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* TODO:
|
2006-03-04 00:32:50 +05:30
|
|
|
* Move to dynamic allocation of (currently statically allocated)
|
2005-10-28 16:51:40 +05:30
|
|
|
* buffers; especially for the group-related functions since
|
|
|
|
* large group member lists will cause error returns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GETXXKEY_R_FUNC
|
|
|
|
#error GETXXKEY_R_FUNC is not defined!
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 02:41:57 +05:30
|
|
|
int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
|
2006-10-05 15:47:08 +05:30
|
|
|
GETXXKEY_R_ENTTYPE *__restrict resultbuf,
|
|
|
|
char *__restrict buffer, size_t buflen,
|
|
|
|
GETXXKEY_R_ENTTYPE **__restrict result)
|
2005-10-28 16:51:40 +05:30
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
2008-07-22 04:35:26 +05:30
|
|
|
stream = fopen_for_read(GETXXKEY_R_PATHNAME);
|
2006-10-05 15:47:08 +05:30
|
|
|
if (!stream)
|
|
|
|
return errno;
|
|
|
|
while (1) {
|
2006-12-31 02:41:57 +05:30
|
|
|
rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
|
2006-10-05 15:47:08 +05:30
|
|
|
if (!rv) {
|
2010-10-29 15:16:52 +05:30
|
|
|
if (GETXXKEY_R_TEST(resultbuf)) { /* found key? */
|
2006-10-05 15:47:08 +05:30
|
|
|
*result = resultbuf;
|
2005-10-28 16:51:40 +05:30
|
|
|
break;
|
|
|
|
}
|
2006-10-05 15:47:08 +05:30
|
|
|
} else {
|
2010-10-29 15:16:52 +05:30
|
|
|
if (rv == ENOENT) { /* EOF encountered */
|
2006-10-05 15:47:08 +05:30
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-10-28 16:51:40 +05:30
|
|
|
}
|
2006-10-05 15:47:08 +05:30
|
|
|
fclose(stream);
|
2005-10-28 16:51:40 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef GETXXKEY_R_FUNC
|
|
|
|
#undef GETXXKEY_R_PARSER
|
|
|
|
#undef GETXXKEY_R_ENTTYPE
|
|
|
|
#undef GETXXKEY_R_TEST
|
2006-12-31 02:41:57 +05:30
|
|
|
#undef GETXXKEY_R_KEYTYPE
|
|
|
|
#undef GETXXKEY_R_PATHNAME
|