diff options
author | David Robillard <d@drobilla.net> | 2024-11-15 09:23:33 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-17 14:40:27 -0500 |
commit | 9e71c9372d25b699d63a8110ab26a3239ca48cd6 (patch) | |
tree | 3415c03bd253bb990d98ee823bb21b5ffa63989e /src/string_utils.c | |
parent | 9e74b423c87f50c6f50cc40cece057e439ddca57 (diff) | |
download | jalv-9e71c9372d25b699d63a8110ab26a3239ca48cd6.tar.gz jalv-9e71c9372d25b699d63a8110ab26a3239ca48cd6.tar.bz2 jalv-9e71c9372d25b699d63a8110ab26a3239ca48cd6.zip |
Move string utilities to a separate compilation unit
These don't really have anything to do with logging. Also replace a call to
the non-standard strdup() in the process.
Diffstat (limited to 'src/string_utils.c')
-rw-r--r-- | src/string_utils.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/string_utils.c b/src/string_utils.c new file mode 100644 index 0000000..a690eb1 --- /dev/null +++ b/src/string_utils.c @@ -0,0 +1,30 @@ +// Copyright 2007-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include "string_utils.h" + +#include <stdlib.h> +#include <string.h> + +char* +jalv_strdup(const char* const str) +{ + const size_t len = strlen(str); + char* copy = (char*)malloc(len + 1); + memcpy(copy, str, len + 1); + return copy; +} + +char* +jalv_strjoin(const char* const a, const char* const b) +{ + const size_t a_len = strlen(a); + const size_t b_len = strlen(b); + char* const out = (char*)malloc(a_len + b_len + 1); + + memcpy(out, a, a_len); + memcpy(out + a_len, b, b_len); + out[a_len + b_len] = '\0'; + + return out; +} |