mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-13 04:15:50 +01:00
- added a new version of wstrappend() with different behavior from the
old one (the one renamed to wstrconcat). The new wstrappend(dst, src) will modify and return dst, without creating a new string to hold the result, except if dst==NULL, in which case its equivalent to calling wstrdup(src)
This commit is contained in:
@@ -76,7 +76,8 @@ static int Aborting=0; /* if we're in the middle of an emergency exit */
|
||||
static WMHashTable *table = NULL;
|
||||
|
||||
|
||||
void *wmalloc(size_t size)
|
||||
void*
|
||||
wmalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
@@ -110,7 +111,8 @@ void *wmalloc(size_t size)
|
||||
}
|
||||
|
||||
|
||||
void *wrealloc(void *ptr, size_t newsize)
|
||||
void*
|
||||
wrealloc(void *ptr, size_t newsize)
|
||||
{
|
||||
void *nptr;
|
||||
|
||||
@@ -228,19 +230,35 @@ wstrdup(char *str)
|
||||
|
||||
|
||||
char*
|
||||
wstrconcat(char *dst, char *src)
|
||||
wstrconcat(char *str1, char *str2)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src)
|
||||
return wstrdup(dst);
|
||||
|
||||
str = wmalloc(strlen(dst)+strlen(src)+1);
|
||||
strcpy(str, dst);
|
||||
strcat(str, src);
|
||||
|
||||
if (!str1)
|
||||
return wstrdup(str2);
|
||||
else if (!str2)
|
||||
return wstrdup(str1);
|
||||
|
||||
str = wmalloc(strlen(str1)+strlen(str2)+1);
|
||||
strcpy(str, str1);
|
||||
strcat(str, str2);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrappend(char *dst, char *src)
|
||||
{
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src || *src==0)
|
||||
return dst;
|
||||
|
||||
dst = wrealloc(dst, strlen(dst)+strlen(src)+1);
|
||||
strcat(dst, src);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user