Commit 849b0563 authored by Max Kellermann's avatar Max Kellermann

util/Alloc: add fallback for gcc 4.6

parent 16a99ad5
...@@ -75,6 +75,8 @@ xstrndup(const char *s, size_t n) ...@@ -75,6 +75,8 @@ xstrndup(const char *s, size_t n)
return p; return p;
} }
#if CLANG_OR_GCC_VERSION(4,7)
template<typename... Args> template<typename... Args>
static inline size_t static inline size_t
FillLengths(size_t *lengths, const char *a, Args&&... args) FillLengths(size_t *lengths, const char *a, Args&&... args)
...@@ -104,11 +106,14 @@ StringCat(char *p, const size_t *lengths, const char *a) ...@@ -104,11 +106,14 @@ StringCat(char *p, const size_t *lengths, const char *a)
memcpy(p, a, *lengths); memcpy(p, a, *lengths);
} }
#endif
template<typename... Args> template<typename... Args>
gcc_malloc gcc_nonnull_all gcc_malloc gcc_nonnull_all
static inline char * static inline char *
t_xstrcatdup(Args&&... args) t_xstrcatdup(Args&&... args)
{ {
#if CLANG_OR_GCC_VERSION(4,7)
constexpr size_t n = sizeof...(args); constexpr size_t n = sizeof...(args);
size_t lengths[n]; size_t lengths[n];
...@@ -118,6 +123,22 @@ t_xstrcatdup(Args&&... args) ...@@ -118,6 +123,22 @@ t_xstrcatdup(Args&&... args)
StringCat(p, lengths, args...); StringCat(p, lengths, args...);
p[total] = 0; p[total] = 0;
return p; return p;
#else
/* fallback implementation for gcc 4.6, because that old
compiler is too buggy to compile the above template
functions */
const char *const argv[] = { args... };
size_t total = 0;
for (auto i : argv)
total += strlen(i);
char *p = (char *)xalloc(total + 1), *q = p;
for (auto i : argv)
q = stpcpy(q, i);
return p;
#endif
} }
char * char *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment