fgetgrent_r.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <ctype.h>
  15. #include <errno.h>
  16. #include <grp.h>
  17. #include <stdio.h>
  18. /* Define a line parsing function using the common code
  19. used in the nss_files module. */
  20. #define STRUCTURE group
  21. #define ENTNAME grent
  22. struct grent_data {};
  23. #define TRAILING_LIST_MEMBER gr_mem
  24. #define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
  25. #include <nss/nss_files/files-parse.c>
  26. LINE_PARSER
  27. (,
  28. STRING_FIELD (result->gr_name, ISCOLON, 0);
  29. if (line[0] == '\0'
  30. && (result->gr_name[0] == '+' || result->gr_name[0] == '-'))
  31. {
  32. result->gr_passwd = NULL;
  33. result->gr_gid = 0;
  34. }
  35. else
  36. {
  37. STRING_FIELD (result->gr_passwd, ISCOLON, 0);
  38. if (result->gr_name[0] == '+' || result->gr_name[0] == '-')
  39. INT_FIELD_MAYBE_NULL (result->gr_gid, ISCOLON, 0, 10, , 0)
  40. else
  41. INT_FIELD (result->gr_gid, ISCOLON, 0, 10,)
  42. }
  43. )
  44. /* Read one entry from the given stream. */
  45. int
  46. __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
  47. struct group **result)
  48. {
  49. int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
  50. if (ret == 0)
  51. *result = resbuf;
  52. else
  53. *result = NULL;
  54. return ret;
  55. }
  56. weak_alias (__fgetgrent_r, fgetgrent_r)