diff options
| author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-10 23:11:01 -0400 | 
|---|---|---|
| committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-10 23:11:01 -0400 | 
| commit | ec34e9ce8a380df87dbf5b455b62e805c00ca8d3 (patch) | |
| tree | f1ba6e9ae5d375d665cb40c83ab83db084c86003 | |
| parent | 88fa909c3cf3c63780feaa5ba92d8bc47f361d63 (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.
| -rw-r--r-- | config.c | 10 | 
1 files changed, 9 insertions, 1 deletions
| @@ -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;  	} | 
