nss_files_fopen.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Open an nss_files database file.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <nss_files.h>
  16. #include <errno.h>
  17. #include <stdio_ext.h>
  18. FILE *
  19. __nss_files_fopen (const char *path)
  20. {
  21. FILE *fp = fopen (path, "rce");
  22. if (fp == NULL)
  23. return NULL;
  24. /* The stream is not shared across threads. */
  25. __fsetlocking (fp, FSETLOCKING_BYCALLER);
  26. /* This tells libio that the file is seekable, and that fp->_offset
  27. is correct, ensuring that __ftello64 is efficient (bug 26257). */
  28. if (__fseeko64 (fp, 0, SEEK_SET) < 0)
  29. {
  30. /* nss_files requires seekable files, to deal with repeated
  31. reads of the same line after reporting ERANGE. */
  32. fclose (fp);
  33. __set_errno (ESPIPE);
  34. return NULL;
  35. }
  36. return fp;
  37. }
  38. libc_hidden_def (__nss_files_fopen)