diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2020-01-31 17:16:27 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2020-01-31 17:16:27 +0300 |
commit | 0be032c6998e712dc2c9f2ed97c3491d89eb05af (patch) | |
tree | f762d884147d2f0a9a115edd0b5e0de554a3ec1b /src/utils.cpp | |
download | xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar.xz xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.zip |
[xift] Almost done.
Diffstat (limited to 'src/utils.cpp')
-rw-r--r-- | src/utils.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..2137aa8 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,36 @@ +#include "utils.hpp" + +#include <stdlib.h> +#include <string.h> + + +char *xift_str_create_copy(const char *begin, const char *end) +{ + char *res; + res = (char *)malloc(end - begin + 1); + if (res) { + memcpy(res, begin, end - begin); + res[end - begin] = 0; + } + return res; +} + + +bool xift_str_add(char *&dest, int &len, int &size, char c) +{ + if (!dest) { + dest = (char *)malloc(2); + size = 2; + len = 0; + } + if (len + 1 == size) { + size *= 2; + dest = (char *)realloc(dest, size); + } + if (dest) { + dest[len] = c; + ++len; + dest[len] = 0; + } + return dest != 0; +} |