Browse Source

lib/strutils: rename strappend() to strconcat()

It concatenates two strings to a new string. It's something else than
"append".

Signed-off-by: Karel Zak <kzak@redhat.com>
pull/1407/head
Karel Zak 1 year ago
parent
commit
8420463b6d
  1. 6
      include/strutils.h
  2. 13
      lib/strutils.c
  3. 2
      lib/strv.c
  4. 2
      libmount/src/tab.c
  5. 2
      misc-utils/getopt.c
  6. 4
      misc-utils/logger.c

6
include/strutils.h

@ -378,9 +378,9 @@ static inline void strrem(char *s, int rem)
*p = '\0';
}
extern char *strnappend(const char *s, const char *suffix, size_t b);
extern char *strappend(const char *s, const char *suffix);
extern char *strfappend(const char *s, const char *format, ...)
extern char *strnconcat(const char *s, const char *suffix, size_t b);
extern char *strconcat(const char *s, const char *suffix);
extern char *strfconcat(const char *s, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern const char *split(const char **state, size_t *l, const char *separator, int quoted);

13
lib/strutils.c

@ -936,7 +936,8 @@ int streq_paths(const char *a, const char *b)
return 0;
}
char *strnappend(const char *s, const char *suffix, size_t b)
/* concatenate two strings to a new string, the size of the second string is limited by @b */
char *strnconcat(const char *s, const char *suffix, size_t b)
{
size_t a;
char *r;
@ -966,12 +967,14 @@ char *strnappend(const char *s, const char *suffix, size_t b)
return r;
}
char *strappend(const char *s, const char *suffix)
/* concatenate two strings to a new string */
char *strconcat(const char *s, const char *suffix)
{
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
return strnconcat(s, suffix, suffix ? strlen(suffix) : 0);
}
char *strfappend(const char *s, const char *format, ...)
/* concatenate @s and string defined by @format to a new string */
char *strfconcat(const char *s, const char *format, ...)
{
va_list ap;
char *val, *res;
@ -984,7 +987,7 @@ char *strfappend(const char *s, const char *format, ...)
if (sz < 0)
return NULL;
res = strnappend(s, val, sz);
res = strnconcat(s, val, sz);
free(val);
return res;
}

2
lib/strv.c

@ -162,7 +162,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) {
STRV_FOREACH(s, b) {
char *v;
v = strappend(*s, suffix);
v = strconcat(*s, suffix);
if (!v)
return -ENOMEM;

2
libmount/src/tab.c

@ -1747,7 +1747,7 @@ int __mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_f
src = mnt_fs_get_srcpath(rootfs);
if (fstype && strncmp(fstype, "nfs", 3) == 0 && root) {
/* NFS stores the root at the end of the source */
src = src2 = strappend(src, root);
src = src2 = strconcat(src, root);
free(root);
root = NULL;
}

2
misc-utils/getopt.c

@ -280,7 +280,7 @@ static void add_short_options(struct getopt_control *ctl, char *options)
{
free(ctl->optstr);
if (*options != '+' && getenv("POSIXLY_CORRECT"))
ctl->optstr = strappend("+", options);
ctl->optstr = strconcat("+", options);
else
ctl->optstr = xstrdup(options);
if (!ctl->optstr)

4
misc-utils/logger.c

@ -654,7 +654,7 @@ static char *strdup_structured_data_list(struct list_head *ls)
if (!one)
continue;
res = strappend(tmp, one);
res = strconcat(tmp, one);
free(tmp);
free(one);
}
@ -672,7 +672,7 @@ static char *get_structured_data_string(struct logger_ctl *ctl)
usr = strdup_structured_data_list(&ctl->user_sds);
if (sys && usr) {
res = strappend(sys, usr);
res = strconcat(sys, usr);
free(sys);
free(usr);
} else

Loading…
Cancel
Save