From 00d03e39fc9fb10b9ebb45f4deb5afa358bf35a1 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Fri, 5 Apr 2024 21:40:19 +0300 Subject: [PATCH] freadln.*: ignore end of transmission --- c-programming/io/freadln.c | 2 +- c-programming/io/freadln.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/c-programming/io/freadln.c b/c-programming/io/freadln.c index 383a4d3..8a74635 100644 --- a/c-programming/io/freadln.c +++ b/c-programming/io/freadln.c @@ -42,7 +42,7 @@ int freadln(FILE* f, char** output, size_t* length_out) { } int character; - while ((character = fgetc(f)) != EOF + while ((character = fgetc(f)) != EOF && character != EOT /* stop on a newline character: */ && character != '\n') { (*output)[length] = (char) character; diff --git a/c-programming/io/freadln.h b/c-programming/io/freadln.h index c98809e..4db8c98 100644 --- a/c-programming/io/freadln.h +++ b/c-programming/io/freadln.h @@ -12,6 +12,8 @@ #include #include +#define EOT 4 /* end of transmission */ + typedef size_t freadln_length_type; enum freadln_status {