1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-04-05 14:45:20 +05:30

freadln: add more flavors

This commit is contained in:
パチュリー・ノーレッジ 2025-03-02 14:08:43 +03:00
parent 39de2a67d8
commit ae4a82c2aa
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
2 changed files with 15 additions and 0 deletions

View File

@ -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 <ctype.h>
# include <inttypes.h>

View File

@ -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 */