3
0

pwd_grp_internal.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /* Copyright (C) 2003 Manuel Novoa III
  3. *
  4. * Licensed under GPL v2, or later. See file LICENSE in this tarball.
  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. */
  19. #ifndef GETXXKEY_R_FUNC
  20. #error GETXXKEY_R_FUNC is not defined!
  21. #endif
  22. int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
  23. GETXXKEY_R_ENTTYPE *__restrict resultbuf,
  24. char *__restrict buffer, size_t buflen,
  25. GETXXKEY_R_ENTTYPE **__restrict result)
  26. {
  27. FILE *stream;
  28. int rv;
  29. *result = NULL;
  30. stream = fopen(DO_GETXXKEY_R_PATHNAME, "r");
  31. if (!stream)
  32. return errno;
  33. while (1) {
  34. rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
  35. if (!rv) {
  36. if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
  37. *result = resultbuf;
  38. break;
  39. }
  40. } else {
  41. if (rv == ENOENT) { /* end-of-file encountered. */
  42. rv = 0;
  43. }
  44. break;
  45. }
  46. }
  47. fclose(stream);
  48. return rv;
  49. }
  50. #undef GETXXKEY_R_FUNC
  51. #undef GETXXKEY_R_PARSER
  52. #undef GETXXKEY_R_ENTTYPE
  53. #undef GETXXKEY_R_TEST
  54. #undef DO_GETXXKEY_R_KEYTYPE
  55. #undef DO_GETXXKEY_R_PATHNAME