]>
Commit | Line | Data |
---|---|---|
299210c1 FW |
1 | /* Open an nss_files database file. |
2 | Copyright (C) 2020 Free Software Foundation, Inc. | |
3 | This file is part of the GNU C Library. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #include <nss_files.h> | |
20 | ||
21 | #include <errno.h> | |
22 | #include <stdio_ext.h> | |
23 | ||
24 | FILE * | |
25 | __nss_files_fopen (const char *path) | |
26 | { | |
27 | FILE *fp = fopen (path, "rce"); | |
28 | if (fp == NULL) | |
29 | return NULL; | |
30 | ||
31 | /* The stream is not shared across threads. */ | |
32 | __fsetlocking (fp, FSETLOCKING_BYCALLER); | |
33 | ||
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) | |
37 | { | |
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; | |
43 | } | |
44 | ||
45 | return fp; | |
46 | } | |
47 | libc_hidden_def (__nss_files_fopen) |