diff options
author | John Hawthorn <john@hawthorn.email> | 2019-08-16 01:17:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-16 01:17:40 -0700 |
commit | b7ff1a61a845253fb090126c6cd9f29f028b66e6 (patch) | |
tree | 5a3662fb7b40386a686e5cdd0d5a0f8adef7f549 /src/choices.c | |
parent | a318e00e30df4056c78ff4edf38376feb4d57dab (diff) | |
parent | 79e48082f579f6c02a55b7cff81ecee1c4127b29 (diff) |
Merge pull request #121 from jhawthorn/read-null
Add -0/--read-null
Diffstat (limited to 'src/choices.c')
-rw-r--r-- | src/choices.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/choices.c b/src/choices.c index a8c24b6..fe2f80b 100644 --- a/src/choices.c +++ b/src/choices.c @@ -46,7 +46,7 @@ static void *safe_realloc(void *buffer, size_t size) { return buffer; } -void choices_fread(choices_t *c, FILE *file) { +void choices_fread(choices_t *c, FILE *file, char input_delimiter) { /* Save current position for parsing later */ size_t buffer_start = c->buffer_size; @@ -72,9 +72,10 @@ void choices_fread(choices_t *c, FILE *file) { */ /* Tokenize input and add to choices */ + const char *line_end = c->buffer + c->buffer_size; char *line = c->buffer + buffer_start; do { - char *nl = strchr(line, '\n'); + char *nl = strchr(line, input_delimiter); if (nl) *nl++ = '\0'; @@ -83,7 +84,7 @@ void choices_fread(choices_t *c, FILE *file) { choices_add(c, line); line = nl; - } while (line); + } while (line && line < line_end); } static void choices_resize(choices_t *c, size_t new_capacity) { |