From 074e15e1fe706c1511416803ad5b8b28e955115e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 1 May 2019 16:24:04 +0200 Subject: Remove trailintg newline from parsed displayname files. --- src/calendar.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/calendar.c b/src/calendar.c index b437d98d..500f0827 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -81,20 +81,29 @@ int handle_dir(vcomponent* cal, char* path) { buf[path_len] = '\0'; FILE* f; - char info_buf[0x100]; + size_t read, size = 0x100; + char* info_buf = malloc(size); if (strcmp (d->d_name, "color") == 0) { f = fopen(resolved_path, "r"); - fgets(info_buf, 0x100, f); - if (info_buf[strlen(info_buf) - 1] == '\n') - info_buf[strlen(info_buf) - 1] = '\0'; + read = getline(&info_buf, &size, f); + if (info_buf[read - 1] == '\n') + info_buf[read - 1] = '\0'; fclose(f); vcomponent_push_val(cal, "COLOR", info_buf); } else if (strcmp (d->d_name, "displayname") == 0) { f = fopen(resolved_path, "r"); - fgets(info_buf, 0x100, f); + read = getline(&info_buf, &size, f); + if (info_buf[read - 1] == '\n') + info_buf[read - 1] = '\0'; + fclose(f); - // TODO make sure that this replaces + + /* This adds the new list to the set of names, keeping the + * filename name. + * This works since *currently* values are returned in + * reverse order + */ vcomponent_push_val(cal, "NAME", info_buf); } else { open_ics (resolved_path, cal); -- cgit v1.2.3