From cea56af185eae45b1f0963351e3d4daa1cbde521 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 2 Apr 2020 17:09:36 +0200 Subject: support: Change xgetline to return 0 on EOF The advantage is that the buffer will always contain the number of characters as returned from the function, which allows one to use a sequence like /* No more audit module output. */ line_length = xgetline (&buffer, &buffer_length, fp); TEST_COMPARE_BLOB ("", 0, buffer, line_length); to check for an expected EOF, while also reporting any unexpected extra data encountered. Reviewed-by: Carlos O'Donell --- support/xstdio.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'support/xstdio.h') diff --git a/support/xstdio.h b/support/xstdio.h index 143957b6a8..807c3afc43 100644 --- a/support/xstdio.h +++ b/support/xstdio.h @@ -27,7 +27,10 @@ __BEGIN_DECLS FILE *xfopen (const char *path, const char *mode); void xfclose (FILE *); -ssize_t xgetline (char **lineptr, size_t *n, FILE *stream); +/* Read a line from FP, using getline. *BUFFER must be NULL, or a + heap-allocated pointer of *LENGTH bytes. Return the number of + bytes in the line if a line was read, or 0 on EOF. */ +size_t xgetline (char **lineptr, size_t *n, FILE *stream); __END_DECLS -- cgit v1.2.3-70-g09d2