diff options
Diffstat (limited to 'support/xgetline.c')
-rw-r--r-- | support/xgetline.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/support/xgetline.c b/support/xgetline.c index 180bc2d..d91c09a 100644 --- a/support/xgetline.c +++ b/support/xgetline.c @@ -18,16 +18,22 @@ #include <support/xstdio.h> #include <support/check.h> -#include <errno.h> -ssize_t +size_t xgetline (char **lineptr, size_t *n, FILE *stream) { - int old_errno = errno; - errno = 0; - size_t ret = getline (lineptr, n, stream); - if (!feof (stream) && ferror (stream)) - FAIL_EXIT1 ("getline failed: %m"); - errno = old_errno; + TEST_VERIFY (!ferror (stream)); + ssize_t ret = getline (lineptr, n, stream); + if (ferror (stream)) + { + TEST_VERIFY (ret < 0); + FAIL_EXIT1 ("getline: %m"); + } + if (feof (stream)) + { + TEST_VERIFY (ret <= 0); + return 0; + } + TEST_VERIFY (ret > 0); return ret; } |