3
0

pwd_grp_internal.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* vi: set sw=4 ts=4: */
  2. /* Copyright (C) 2003 Manuel Novoa III
  3. *
  4. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  5. */
  6. /* Nov 6, 2003 Initial version.
  7. *
  8. * NOTE: This implementation is quite strict about requiring all
  9. * field seperators. It also does not allow leading whitespace
  10. * except when processing the numeric fields. glibc is more
  11. * lenient. See the various glibc difference comments below.
  12. *
  13. * TODO:
  14. * Move to dynamic allocation of (currently statically allocated)
  15. * buffers; especially for the group-related functions since
  16. * large group member lists will cause error returns.
  17. */
  18. #ifndef GETXXKEY_R_FUNC
  19. #error GETXXKEY_R_FUNC is not defined!
  20. #endif
  21. int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
  22. GETXXKEY_R_ENTTYPE *__restrict resultbuf,
  23. char *__restrict buffer, size_t buflen,
  24. GETXXKEY_R_ENTTYPE **__restrict result)
  25. {
  26. FILE *stream;
  27. int rv;
  28. *result = NULL;
  29. stream = fopen_for_read(GETXXKEY_R_PATHNAME);
  30. if (!stream)
  31. return errno;
  32. while (1) {
  33. rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
  34. if (!rv) {
  35. if (GETXXKEY_R_TEST(resultbuf)) { /* found key? */
  36. *result = resultbuf;
  37. break;
  38. }
  39. } else {
  40. if (rv == ENOENT) { /* EOF encountered */
  41. rv = 0;
  42. }
  43. break;
  44. }
  45. }
  46. fclose(stream);
  47. return rv;
  48. }
  49. #undef GETXXKEY_R_FUNC
  50. #undef GETXXKEY_R_PARSER
  51. #undef GETXXKEY_R_ENTTYPE
  52. #undef GETXXKEY_R_TEST
  53. #undef GETXXKEY_R_KEYTYPE
  54. #undef GETXXKEY_R_PATHNAME