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