1/* Internal routines for nss_files.
2 Copyright (C) 2020-2021 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. */
25FILE *__nss_files_fopen (const char *path);
26libc_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). */
33int __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset);
34libc_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. */
41int __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). */
47int __nss_parse_line_result (FILE *fp, off64_t offset, int parse_line_result);
48libc_hidden_proto (__nss_parse_line_result)
49
50struct parser_data;
51
52/* Instances of the parse_line function from
53 nss/nss_files/files-parse.c. */
54typedef int nss_files_parse_line (char *line, void *result,
55 struct parser_data *data,
56 size_t datalen, int *errnop);
57extern nss_files_parse_line _nss_files_parse_etherent;
58extern nss_files_parse_line _nss_files_parse_grent;
59extern nss_files_parse_line _nss_files_parse_netent;
60extern nss_files_parse_line _nss_files_parse_protoent;
61extern nss_files_parse_line _nss_files_parse_pwent;
62extern nss_files_parse_line _nss_files_parse_rpcent;
63extern nss_files_parse_line _nss_files_parse_servent;
64extern nss_files_parse_line _nss_files_parse_sgent;
65extern nss_files_parse_line _nss_files_parse_spent;
66
67libnss_files_hidden_proto (_nss_files_parse_etherent)
68libc_hidden_proto (_nss_files_parse_grent)
69libnss_files_hidden_proto (_nss_files_parse_netent)
70libnss_files_hidden_proto (_nss_files_parse_protoent)
71libc_hidden_proto (_nss_files_parse_pwent)
72libnss_files_hidden_proto (_nss_files_parse_rpcent)
73libnss_files_hidden_proto (_nss_files_parse_servent)
74libc_hidden_proto (_nss_files_parse_sgent)
75libc_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. */
80int __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