diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2020-03-11 17:54:19 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2020-03-11 17:54:19 +0300 |
commit | 8f1e6faa7f548c9a8bcbcac71c8f239a6540b926 (patch) | |
tree | dd5dfec60de8e52472fe8db2b5ae66010d5dc1d3 /src/tools.c | |
parent | 5cfe6cdf6af2d630d21871f9193fc1b4a7db24ff (diff) | |
download | magi-8f1e6faa7f548c9a8bcbcac71c8f239a6540b926.tar magi-8f1e6faa7f548c9a8bcbcac71c8f239a6540b926.tar.xz magi-8f1e6faa7f548c9a8bcbcac71c8f239a6540b926.zip |
[magi]
Diffstat (limited to 'src/tools.c')
-rw-r--r-- | src/tools.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/tools.c b/src/tools.c index d7a90ce..d6170bc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -19,37 +19,27 @@ char *magi_str_lowercase(char *str) char *magi_str_create_copy(const char *first, int len) { char *copy = magi_str_create(len); - if (copy) { - memcpy(copy, first, len); - } + memcpy(copy, first, len); return copy; } char *magi_str_create(int len) { char *str = malloc(len + 1); - if (str) { - str[len] = 0; - } + str[len] = 0; return str; } -int magi_str_add(magi_str *str, char c) +void magi_str_add(char **str, int *len, int *size, char c) { - if (!str->data) { - str->len = 0; - str->size = 2; - str->data = malloc(2); - } else if (str->len + 1 == str->size) { - str->size *= 2; - str->data = realloc(str->data, str->size); - } - if (!str->dest) { - str->len = 0; - str->size = 0; - return 0; + if (!*str) { + *len = 0; + *size = 2; + *str = malloc(2); + } else if (*len + 1 == *size) { + *size *= 2; + *str = realloc(*str, *size); } - str->data[str->len++] = c; - str->data[str->len] = 0; - return 1; + *str[*len] = c; + *str[++*len] = 0; } |