From acbd792900767949c5836e3fc401b134ab93e144 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 10 Dec 2019 16:08:42 -0500 Subject: Fix minor bugs and implement rsync function --- config.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 6e6ae8a..c35c233 100644 --- a/config.c +++ b/config.c @@ -91,7 +91,9 @@ ConfigItem **config_read(const char *filename) { continue; } - // Calculate key and value lengths dynamically + // These values are approximations. The real length(s) are recorded using strlen below. + // At most we'll lose a few heap bytes to whitespace, but it's better than allocating PATH_MAX or BUFSIZ + // for a measly ten byte string. size_t key_length = strcspn(lptr, &sep); size_t value_length = strlen(sep_pos); @@ -104,6 +106,10 @@ ConfigItem **config_read(const char *filename) { char *key = config[record]->key; char *value = config[record]->value; + // Copy the array pointers (used to populate config->key/value_length + char *key_orig = key; + char *value_orig = value; + // Populate the key and remove any trailing space while (lptr != sep_pos) { *key++ = *lptr++; @@ -134,6 +140,10 @@ ConfigItem **config_read(const char *filename) { *value++ = *lptr++; } + // Populate length data + config[record]->key_length = strlen(key_orig); + config[record]->value_length = strlen(value_orig); + // increment record count record++; // Expand config by another record -- cgit