This commit is contained in:
2023-09-05 09:09:55 +02:00
parent 773c8549f3
commit 4451879e35
7 changed files with 90 additions and 55 deletions

View File

@@ -1,4 +1,3 @@
/*
*
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
@@ -11,11 +10,11 @@
#include <cstring.h>
#define INIT_CAPA 64
#define INIT_CAPA 1
/* String container */
void* cstring_init(cstring_t* str) {
str->data = malloc(INIT_CAPA + 1);
str->data = malloc((INIT_CAPA + 1)*sizeof(char));
if (str->data == NULL) return NULL;
memset(str->data, '\0', INIT_CAPA + 1);
str->capa = INIT_CAPA;
@@ -27,9 +26,9 @@ void* cstring_init(cstring_t* str) {
void* cstring_append(cstring_t* str, char* add) {
size_t addsize = strlen(add);
size_t newsize = str->size + addsize;
if (newsize >= str->capa) {
size_t newcapa = newsize + 1;
char* newstr = realloc(str->data, newcapa);
if (newsize > str->capa) {
size_t newcapa = str->capa + addsize;
char* newstr = realloc(str->data, (newcapa + 1)*sizeof(char));
if (newstr == NULL) return NULL;
str->data = newstr;
str->capa = newcapa;