about summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-07-15 13:41:31 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-07-21 07:33:50 +0200
commitbdee910e88006ae33dc83ac3d2c0708adb6627d0 (patch)
treec80cd50103ca8a413cccd589511abea88720e6b2 /include
parentd4b4586315974d2471486d41891aa9463a5838ad (diff)
downloadglibc-bdee910e88006ae33dc83ac3d2c0708adb6627d0.tar.gz
glibc-bdee910e88006ae33dc83ac3d2c0708adb6627d0.tar.xz
glibc-bdee910e88006ae33dc83ac3d2c0708adb6627d0.zip
nss: Add __nss_fgetent_r
And helper functions __nss_readline, __nss_readline_seek,
 __nss_parse_line_result.

This consolidates common code for handling overlong lines and
parse files.  Use the new functionality in internal_getent
in nss/nss_files/files-XXX.c.

Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/nss_files.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/nss_files.h b/include/nss_files.h
index d0f26815b5..f45ea02dc0 100644
--- a/include/nss_files.h
+++ b/include/nss_files.h
@@ -25,6 +25,28 @@
 FILE *__nss_files_fopen (const char *path);
 libc_hidden_proto (__nss_files_fopen)
 
+/* Read a line from FP, storing it BUF.  Strip leading blanks and skip
+   comments.  Sets errno and returns error code on failure.  Special
+   failure: ERANGE means the buffer is too small.  The function writes
+   the original offset to *POFFSET (which can be negative in the case
+   of non-seekable input).  */
+int __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset);
+libc_hidden_proto (__nss_readline)
+
+/* Seek FP to OFFSET.  Sets errno and returns error code on failure.
+   On success, sets errno to ERANGE and returns ERANGE (to indicate
+   re-reading of the same input line to the caller).  If OFFSET is
+   negative, fail with ESPIPE without seeking.  Intended to be used
+   after parsing data read by __nss_readline failed with ERANGE.  */
+int __nss_readline_seek (FILE *fp, off64_t offset) attribute_hidden;
+
+/* Handles the result of a parse_line call (as defined by
+   nss/nss_files/files-parse.c).  Adjusts the file offset of FP as
+   necessary.  Returns 0 on success, and updates errno on failure (and
+   returns that error code).  */
+int __nss_parse_line_result (FILE *fp, off64_t offset, int parse_line_result);
+libc_hidden_proto (__nss_parse_line_result)
+
 struct parser_data;
 
 /* Instances of the parse_line function from
@@ -52,4 +74,11 @@ libnss_files_hidden_proto (_nss_files_parse_servent)
 libc_hidden_proto (_nss_files_parse_sgent)
 libc_hidden_proto (_nss_files_parse_spent)
 
+/* Generic implementation of fget*ent_r.  Reads lines from FP until
+   EOF or a successful parse into *RESULT using PARSER.  Returns 0 on
+   success, ENOENT on EOF, ERANGE on too-small buffer.  */
+int __nss_fgetent_r (FILE *fp, void *result,
+                     char *buffer, size_t buffer_length,
+                     nss_files_parse_line parser) attribute_hidden;
+
 #endif /* _NSS_FILES_H */