summaryrefslogtreecommitdiff
path: root/src/utils.cpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-01-31 17:16:27 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-01-31 17:16:27 +0300
commit0be032c6998e712dc2c9f2ed97c3491d89eb05af (patch)
treef762d884147d2f0a9a115edd0b5e0de554a3ec1b /src/utils.cpp
downloadxift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar
xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.tar.xz
xift-0be032c6998e712dc2c9f2ed97c3491d89eb05af.zip
[xift] Almost done.
Diffstat (limited to 'src/utils.cpp')
-rw-r--r--src/utils.cpp36
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;
+}