2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2010-08-16 18:14:46 +00:00
|
|
|
/* Copyright (C) 2003 Manuel Novoa III
|
2005-10-28 11:21:40 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2005-10-28 11:21:40 +00:00
|
|
|
*/
|
|
|
|
|
2010-08-16 18:14:46 +00:00
|
|
|
/* Nov 6, 2003 Initial version.
|
2005-10-28 11:21:40 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* NOTE: This implementation is quite strict about requiring all
|
2005-10-28 11:21:40 +00:00
|
|
|
* 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 18:14:46 +00:00
|
|
|
* TODO:
|
2006-03-03 19:02:50 +00:00
|
|
|
* Move to dynamic allocation of (currently statically allocated)
|
2005-10-28 11:21:40 +00:00
|
|
|
* 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-30 21:11:57 +00:00
|
|
|
int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
|
2006-10-05 10:17:08 +00:00
|
|
|
GETXXKEY_R_ENTTYPE *__restrict resultbuf,
|
|
|
|
char *__restrict buffer, size_t buflen,
|
|
|
|
GETXXKEY_R_ENTTYPE **__restrict result)
|
2005-10-28 11:21:40 +00:00
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
2008-07-21 23:05:26 +00:00
|
|
|
stream = fopen_for_read(GETXXKEY_R_PATHNAME);
|
2006-10-05 10:17:08 +00:00
|
|
|
if (!stream)
|
|
|
|
return errno;
|
|
|
|
while (1) {
|
2006-12-30 21:11:57 +00:00
|
|
|
rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
|
2006-10-05 10:17:08 +00:00
|
|
|
if (!rv) {
|
|
|
|
if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
|
|
|
|
*result = resultbuf;
|
2005-10-28 11:21:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-05 10:17:08 +00:00
|
|
|
} else {
|
|
|
|
if (rv == ENOENT) { /* end-of-file encountered. */
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-10-28 11:21:40 +00:00
|
|
|
}
|
2006-10-05 10:17:08 +00:00
|
|
|
fclose(stream);
|
2005-10-28 11:21:40 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef GETXXKEY_R_FUNC
|
|
|
|
#undef GETXXKEY_R_PARSER
|
|
|
|
#undef GETXXKEY_R_ENTTYPE
|
|
|
|
#undef GETXXKEY_R_TEST
|
2006-12-30 21:11:57 +00:00
|
|
|
#undef GETXXKEY_R_KEYTYPE
|
|
|
|
#undef GETXXKEY_R_PATHNAME
|