From ae4a82c2aa113e49e7b5ebd344acb88e9d5f45c8 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sun, 2 Mar 2025 14:08:43 +0300 Subject: [PATCH] freadln: add more flavors --- c-programming/io/freadln.c | 9 +++++++++ c-programming/io/freadln.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/c-programming/io/freadln.c b/c-programming/io/freadln.c index 647cabc..7a35ae6 100644 --- a/c-programming/io/freadln.c +++ b/c-programming/io/freadln.c @@ -79,6 +79,15 @@ int freadln(FILE* f, char** output, size_t* length_out) { return freadln_OK; } +inline char* freadln_ptr(FILE* f, size_t* length_out) { + char* output = NULL; + + if (freadln(f, &output, length_out) == freadln_OK) + return output; + + return NULL; +} + #ifdef TEST # include # include diff --git a/c-programming/io/freadln.h b/c-programming/io/freadln.h index 6449fb4..b8c778e 100644 --- a/c-programming/io/freadln.h +++ b/c-programming/io/freadln.h @@ -30,6 +30,12 @@ enum freadln_status { } while (0) int freadln(FILE* f, char** output, size_t* length_out); +char* freadln_ptr(FILE* f, size_t* length_out); +#define freadln_stream(f, output) freadln(f, output, NULL) +#define freadln_ptr_stream(f) freadln_ptr(f, NULL) #define finreadln(output, length_out) freadln(stdin, output, length_out) +#define finreadln_ptr(length_out) freadln_ptr(stdin, length_out) +#define finreadln_stream(output) freadln(stdin, output, NULL) +#define finreadln_ptr_stream() freadln_ptr(stdin, NULL) #endif /* _FREADLN_H */