From: Karel Zak Date: Thu, 5 Aug 2021 09:25:54 +0000 (+0200) Subject: lib/strutils: rename strappend() to strconcat() X-Git-Tag: v2.38-rc1~321 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8420463b6d4cb30251e8a79b7fa3c19b0091da8e;p=thirdparty%2Futil-linux.git 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 --- diff --git a/include/strutils.h b/include/strutils.h index d6f57c71e0..e7edd852e3 100644 --- a/include/strutils.h +++ b/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); diff --git a/lib/strutils.c b/lib/strutils.c index cd49b97817..794203abd1 100644 --- a/lib/strutils.c +++ b/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; } diff --git a/lib/strv.c b/lib/strv.c index ddc2a0c5dd..58a4c97dec 100644 --- a/lib/strv.c +++ b/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; diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 0d5c11566c..5fd4608646 100644 --- a/libmount/src/tab.c +++ b/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; } diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index 3fc38c97d3..977b725600 100644 --- a/misc-utils/getopt.c +++ b/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) diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 5b122de79f..ba36b0fd9c 100644 --- a/misc-utils/logger.c +++ b/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