mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
nasmlib: add nasm_strappend()
nasm_strappend() is similar to nasm_strcat() for the case where the first string isn't useful and should be freed. Furthermore, one or both of the arguments are allowed to be NULL. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
parent
d2cdb72e88
commit
a227b43b8a
2 changed files with 20 additions and 0 deletions
|
|
@ -80,6 +80,7 @@ void nasm_free(void *);
|
|||
char * safe_alloc nasm_strdup(const char *);
|
||||
char * safe_alloc nasm_strndup(const char *, size_t);
|
||||
char * safe_alloc nasm_strcat(const char *one, const char *two);
|
||||
char * never_null nasm_strappend(char *one, const char *two);
|
||||
char * safe_alloc end_with_null nasm_strcatn(const char *one, ...);
|
||||
|
||||
/* Assert the argument is a pointer without evaluating it */
|
||||
|
|
|
|||
|
|
@ -110,6 +110,25 @@ char *nasm_strcat(const char *one, const char *two)
|
|||
return rslt;
|
||||
}
|
||||
|
||||
/* Unlike nasm_strcat() this frees the initial string, which can be NULL */
|
||||
char *nasm_strappend(char *one, const char *two)
|
||||
{
|
||||
size_t l1, l2;
|
||||
|
||||
if (!two)
|
||||
return one;
|
||||
|
||||
if (!one)
|
||||
return nasm_strdup(two);
|
||||
|
||||
l1 = strlen(one);
|
||||
l2 = strlen(two) + 1;
|
||||
one = nasm_realloc(one, l1+l2);
|
||||
memcpy(one + l1, two, l2);
|
||||
|
||||
return one;
|
||||
}
|
||||
|
||||
char *nasm_strcatn(const char *str1, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue