| 1 | /* Internal routines for nss_files. |
| 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 | #ifndef _NSS_FILES_H |
| 20 | #define _NSS_FILES_H |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | /* Open PATH for reading, as a data source for nss_files. */ |
| 25 | FILE *__nss_files_fopen (const char *path); |
| 26 | libc_hidden_proto (__nss_files_fopen) |
| 27 | |
| 28 | /* Read a line from FP, storing it BUF. Strip leading blanks and skip |
| 29 | comments. Sets errno and returns error code on failure. Special |
| 30 | failure: ERANGE means the buffer is too small. The function writes |
| 31 | the original offset to *POFFSET (which can be negative in the case |
| 32 | of non-seekable input). */ |
| 33 | int __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset); |
| 34 | libc_hidden_proto (__nss_readline) |
| 35 | |
| 36 | /* Seek FP to OFFSET. Sets errno and returns error code on failure. |
| 37 | On success, sets errno to ERANGE and returns ERANGE (to indicate |
| 38 | re-reading of the same input line to the caller). If OFFSET is |
| 39 | negative, fail with ESPIPE without seeking. Intended to be used |
| 40 | after parsing data read by __nss_readline failed with ERANGE. */ |
| 41 | int __nss_readline_seek (FILE *fp, off64_t offset) attribute_hidden; |
| 42 | |
| 43 | /* Handles the result of a parse_line call (as defined by |
| 44 | nss/nss_files/files-parse.c). Adjusts the file offset of FP as |
| 45 | necessary. Returns 0 on success, and updates errno on failure (and |
| 46 | returns that error code). */ |
| 47 | int __nss_parse_line_result (FILE *fp, off64_t offset, int parse_line_result); |
| 48 | libc_hidden_proto (__nss_parse_line_result) |
| 49 | |
| 50 | struct parser_data; |
| 51 | |
| 52 | /* Instances of the parse_line function from |
| 53 | nss/nss_files/files-parse.c. */ |
| 54 | typedef int nss_files_parse_line (char *line, void *result, |
| 55 | struct parser_data *data, |
| 56 | size_t datalen, int *errnop); |
| 57 | extern nss_files_parse_line _nss_files_parse_etherent; |
| 58 | extern nss_files_parse_line _nss_files_parse_grent; |
| 59 | extern nss_files_parse_line _nss_files_parse_netent; |
| 60 | extern nss_files_parse_line _nss_files_parse_protoent; |
| 61 | extern nss_files_parse_line _nss_files_parse_pwent; |
| 62 | extern nss_files_parse_line _nss_files_parse_rpcent; |
| 63 | extern nss_files_parse_line _nss_files_parse_servent; |
| 64 | extern nss_files_parse_line _nss_files_parse_sgent; |
| 65 | extern nss_files_parse_line _nss_files_parse_spent; |
| 66 | |
| 67 | libnss_files_hidden_proto (_nss_files_parse_etherent) |
| 68 | libc_hidden_proto (_nss_files_parse_grent) |
| 69 | libnss_files_hidden_proto (_nss_files_parse_netent) |
| 70 | libnss_files_hidden_proto (_nss_files_parse_protoent) |
| 71 | libc_hidden_proto (_nss_files_parse_pwent) |
| 72 | libnss_files_hidden_proto (_nss_files_parse_rpcent) |
| 73 | libnss_files_hidden_proto (_nss_files_parse_servent) |
| 74 | libc_hidden_proto (_nss_files_parse_sgent) |
| 75 | libc_hidden_proto (_nss_files_parse_spent) |
| 76 | |
| 77 | /* Generic implementation of fget*ent_r. Reads lines from FP until |
| 78 | EOF or a successful parse into *RESULT using PARSER. Returns 0 on |
| 79 | success, ENOENT on EOF, ERANGE on too-small buffer. */ |
| 80 | int __nss_fgetent_r (FILE *fp, void *result, |
| 81 | char *buffer, size_t buffer_length, |
| 82 | nss_files_parse_line parser) attribute_hidden; |
| 83 | |
| 84 | #endif /* _NSS_FILES_H */ |
| 85 | |