X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=7dfabbc07d7701802790921e690fb805b83e0e25;hb=374c22b351e43ce4ef70ef0ad1bd1e4e520f9a28;hp=531242213490161c7572c25311c2d121289710fd;hpb=5ffa8c818120e35c89becd938d160235c069dd12;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 531242213..7dfabbc07 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -860,7 +860,7 @@ static inline unsigned u32ctz(uint32_t n) { #endif } -static inline int log2i(int x) { +static inline unsigned log2i(int x) { assert(x > 0); return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1; @@ -872,6 +872,16 @@ static inline unsigned log2u(unsigned x) { return sizeof(unsigned) * 8 - __builtin_clz(x) - 1; } +static inline unsigned log2u64(uint64_t x) { + assert(x > 0); + +#if __SIZEOF_LONG_LONG__ == 8 + return 64 - __builtin_clzll(x) - 1; +#else +#error "Wut?" +#endif +} + static inline unsigned log2u_round_up(unsigned x) { assert(x > 0); @@ -921,19 +931,19 @@ int unlink_noerrno(const char *path); (void*)memset(_new_, 0, _size_); \ }) -#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 strjoina(a, ...) \ + ({ \ + const char *_appendees_[] = { a, __VA_ARGS__ }; \ + char *_d_, *_p_; \ + int _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_; \ }) #define procfs_file_alloca(pid, field) \