Skip to content

Instantly share code, notes, and snippets.

@bartman
Created February 8, 2018 17:29
Show Gist options
  • Save bartman/27048a7981962ff0bcbe75ca671da2c1 to your computer and use it in GitHub Desktop.
Save bartman/27048a7981962ff0bcbe75ca671da2c1 to your computer and use it in GitHub Desktop.
strjoina
pulled from
https://github.com/systemd/systemd
#define strjoina(a, ...) \
({ \
const char *_appendees_[] = { a, __VA_ARGS__ }; \
char *_d_, *_p_; \
size_t _len_ = 0; \
unsigned _i_; \
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
_len_ += strlen(_appendees_[_i_]); \
_p_ = _d_ = alloca(_len_ + 1); \
for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \
_p_ = stpcpy(_p_, _appendees_[_i_]); \
*_p_ = 0; \
_d_; \
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment