summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-03-11 10:41:22 -0400
committerDave Reisner <dreisner@archlinux.org>2014-08-13 20:41:41 -0400
commit8085f163c50d998f3e30a6ddfc72c73d5dc57747 (patch)
tree36184a2129cd3ee2743b1815242ed7ab5c2ee0f7 /src/shared
parentd06441da04cd5102816858d8d1e4aa367c00156b (diff)
util: allow strappenda to take any number of args
This makes strappenda3 redundant, so we remove its usage and definition. Add a few tests along the way for sanity.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c2
-rw-r--r--src/shared/util.h36
2 files changed, 14 insertions, 24 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 276ca3ec7a..0fe1371129 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1061,7 +1061,7 @@ static int unit_file_load(
assert(path);
if (!isempty(root_dir))
- path = strappenda3(root_dir, "/", path);
+ path = strappenda(root_dir, "/", path);
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|(allow_symlink ? 0 : O_NOFOLLOW));
if (fd < 0)
diff --git a/src/shared/util.h b/src/shared/util.h
index 8231cf27bc..101d2dfcf8 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -845,29 +845,19 @@ int unlink_noerrno(const char *path);
(void *) memset(_new_, 0, _len_); \
})
-#define strappenda(a, b) \
- ({ \
- const char *_a_ = (a), *_b_ = (b); \
- char *_c_; \
- size_t _x_, _y_; \
- _x_ = strlen(_a_); \
- _y_ = strlen(_b_); \
- _c_ = alloca(_x_ + _y_ + 1); \
- strcpy(stpcpy(_c_, _a_), _b_); \
- _c_; \
- })
-
-#define strappenda3(a, b, c) \
- ({ \
- const char *_a_ = (a), *_b_ = (b), *_c_ = (c); \
- char *_d_; \
- size_t _x_, _y_, _z_; \
- _x_ = strlen(_a_); \
- _y_ = strlen(_b_); \
- _z_ = strlen(_c_); \
- _d_ = alloca(_x_ + _y_ + _z_ + 1); \
- strcpy(stpcpy(stpcpy(_d_, _a_), _b_), _c_); \
- _d_; \
+#define strappenda(a, ...) \
+ ({ \
+ int _len = strlen(a); \
+ unsigned _i; \
+ char *_d_, *_p_; \
+ const char *_appendees_[] = { __VA_ARGS__ }; \
+ for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \
+ _len += strlen(_appendees_[_i]); \
+ _d_ = alloca(_len + 1); \
+ _p_ = stpcpy(_d_, a); \
+ for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \
+ _p_ = stpcpy(_p_, _appendees_[_i]); \
+ _d_; \
})
#define procfs_file_alloca(pid, field) \