aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-12-10 16:08:42 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-12-10 16:08:42 -0500
commitacbd792900767949c5836e3fc401b134ab93e144 (patch)
tree92445db3b343d1515646f203427b65c2fcaacbb9 /config.c
parentaaac7bc7fb88bb21ee46e42bc3b664a1163e0e6f (diff)
downloadspmc-acbd792900767949c5836e3fc401b134ab93e144.tar.gz
Fix minor bugs and implement rsync function
Diffstat (limited to 'config.c')
-rw-r--r--config.c12
1 files changed, 11 insertions, 1 deletions
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