From 3638c9eb7c3e45cd5db1056fe7ecc77f27973bf9 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sun, 10 Mar 2024 15:25:59 +0300 Subject: [PATCH] freadln.*: fix error handling logic --- c-programming/io/freadln.c | 9 ++++++--- c-programming/io/freadln.h | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/c-programming/io/freadln.c b/c-programming/io/freadln.c index 9a56378..23de41d 100644 --- a/c-programming/io/freadln.c +++ b/c-programming/io/freadln.c @@ -51,7 +51,8 @@ int freadln(FILE* f, char** output, size_t* length_out) { if ((freadln_length_type) (length + 2) <= (freadln_length_type) length) { errno = ERANGE; - freadln_success_epilogue; + freadln_epilogue; + return freadln_ERROR; } else length++; @@ -61,14 +62,16 @@ int freadln(FILE* f, char** output, size_t* length_out) { // has already been accumulated. if (temp == NULL) { // keep errno; - freadln_success_epilogue; + freadln_epilogue; + return freadln_ERROR; } *output = temp; } errno = 0; - freadln_success_epilogue; + freadln_epilogue; + return freadln_OK; } #ifdef TEST diff --git a/c-programming/io/freadln.h b/c-programming/io/freadln.h index 912a9ab..75af727 100644 --- a/c-programming/io/freadln.h +++ b/c-programming/io/freadln.h @@ -19,11 +19,10 @@ enum freadln_status { freadln_ERROR }; -#define freadln_success_epilogue do { \ +#define freadln_epilogue do { \ (*output)[length] = '\0'; \ if (length_out != NULL) \ *length_out = length; \ - return freadln_OK; \ } while (0) int freadln(FILE* f, char** output, size_t* length_out);