Created
February 8, 2018 17:29
-
-
Save bartman/27048a7981962ff0bcbe75ca671da2c1 to your computer and use it in GitHub Desktop.
strjoina
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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