Skip to content

Commit

Permalink
#17 rexgen removes trailing newlines in callback()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Starke committed Jun 20, 2017
1 parent 5c90b45 commit 9f1f824
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/rexgen/rexgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down

0 comments on commit 9f1f824

Please sign in to comment.