htex

simple incorrect html parser
git clone git://git.relim.de/htex.git
Log | Files | Refs | README

commit 4f192e544a2ed77e2d9c7399e48cd5c2c71588ad
parent ddc4977563c877502114bcf5163a12dfa5c3a99e
Author: Robin <kroekerrobin@gmail.com>
Date:   Wed,  3 Apr 2024 13:43:44 +0200

Imporove stringCat function

Diffstat:
Mmisc.c | 25+++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/misc.c b/misc.c @@ -1,22 +1,15 @@ char *stringCat(char *str1, char *str2) { - int str1Len = 0; - int str2Len = 0; - if (str1) - str1Len = strlen(str1); - if (str2) - str2Len = strlen(str2); - char *string = malloc((str1Len+str2Len+1) * sizeof(char)); - int i = 0; - int k = 0; - for (; i<str1Len; i++) - string[i] = str1[i]; - for (; k<str2Len; k++) - string[i+k] = str2[k]; - string[i+k] = '\0'; - free(str1); + size_t len2 = strlen(str2); + if (str1 == NULL) { + str1 = realloc(str1, (len2+1) * sizeof(char)); + strcpy(str1, str2); + } else { + str1 = realloc(str1, (strlen(str1)+len2+1) * sizeof(char)); + strcat(str1, str2); + } free(str2); - return string; + return str1; } char *cpToChars(uint_least32_t cp, size_t len)