summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-10 23:11:01 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-10 23:11:01 -0400
commitec34e9ce8a380df87dbf5b455b62e805c00ca8d3 (patch)
treef1ba6e9ae5d375d665cb40c83ab83db084c86003 /config.c
parent88fa909c3cf3c63780feaa5ba92d8bc47f361d63 (diff)
Added the `make_str()` function.
This function automatically allocates a string that's the same size of the supplied string, and copies it to this newly allocated string, which is then returned. Since this uses `malloc()`, it must be `free()`'d after it's been used.
Diffstat (limited to 'config.c')
-rw-r--r--config.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/config.c b/config.c
index 6847587..f0622c5 100644
--- a/config.c
+++ b/config.c
@@ -72,13 +72,21 @@ char *get_line(char **str) {
return s;
}
+char *make_str(const char *str) {
+ const size_t length = strlen(str);
+ char *s = malloc(length+1);
+ memset(s, 0, length+1);
+ memcpy(s, str, length);
+ return s;
+}
+
config_val parse_option_value(const config_opt *opt, char *value) {
config_val val = {0};
switch (opt->type) {
case TYPE_INT :
case TYPE_BOOL : val.i = strtol(value, NULL, 0); break;
- case TYPE_STRING: val.str = value; break;
+ case TYPE_STRING: val.str = make_str(value); break;
case TYPE_FLOAT : val.f = strtof(value, NULL); break;
default : break;
}