summaryrefslogtreecommitdiff
path: root/src/choices.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/choices.c')
-rw-r--r--src/choices.c7
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) {