From 9f1f824d90b2a040941b754a0ba8375a09d70208 Mon Sep 17 00:00:00 2001 From: Jan Starke Date: Tue, 20 Jun 2017 10:12:08 +0200 Subject: [PATCH] #17 rexgen removes trailing newlines in callback() --- src/rexgen/rexgen.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/rexgen/rexgen.c b/src/rexgen/rexgen.c index 66f1cfb..6444282 100644 --- a/src/rexgen/rexgen.c +++ b/src/rexgen/rexgen.c @@ -168,13 +168,21 @@ const char* rexgen_parse_arguments(int argc, _TCHAR** argv) { */ size_t callback(char* dst, const size_t buffer_size) { + size_t len = 0; + while (len == 0) { + /* read next word */ + if (fgets(dst, buffer_size, infile) == NULL) { + return 0; + } - /* read next word */ - if (fgets((char*)dst, buffer_size, infile) == NULL) { - return 0; + /* remove trailing newlines */ + len = strnlen(dst, buffer_size); + while (len > 0 && dst[len - 1] == '\n') { + --len; + dst[len] = '\0'; + } } - - return strlen((char*)dst); + return len; } int _tmain(int argc, _TCHAR* argv[]) {