X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=e405b02a8189760d4a9a773c160f330baba20bc7;hb=1caa12d0a8a818d5f2545aab809b3fdfec73871d;hp=a1d5657237368803ef9c6ab8e781d3670ddff132;hpb=95d78c7e7c81a6b788f28c33ef2cafd87471a0d7;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index a1d565723..e405b02a8 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -205,7 +205,7 @@ int safe_atod(const char *s, double *ret_d); int safe_atou8(const char *s, uint8_t *ret); -#if __WORDSIZE == 32 +#if LONG_MAX == INT_MAX static inline int safe_atolu(const char *s, unsigned long *ret_u) { assert_cc(sizeof(unsigned long) == sizeof(unsigned)); return safe_atou(s, (unsigned*) ret_u); @@ -321,6 +321,7 @@ int make_console_stdio(void); int dev_urandom(void *p, size_t n); void random_bytes(void *p, size_t n); +void initialize_srand(void); static inline uint64_t random_u64(void) { uint64_t u; @@ -829,6 +830,21 @@ static inline int log2i(int x) { return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1; } +static inline unsigned log2u(unsigned x) { + assert(x > 0); + + return sizeof(unsigned) * 8 - __builtin_clz(x) - 1; +} + +static inline unsigned log2u_round_up(unsigned x) { + assert(x > 0); + + if (x == 1) + return 0; + + return log2u(x - 1) + 1; +} + static inline bool logind_running(void) { return access("/run/systemd/seats/", F_OK) >= 0; } @@ -991,8 +1007,11 @@ bool is_localhost(const char *hostname); int take_password_lock(const char *root); int is_symlink(const char *path); +int is_dir(const char *path, bool follow); int unquote_first_word(const char **p, char **ret); int unquote_many_words(const char **p, ...) _sentinel_; int free_and_strdup(char **p, const char *s); + +int sethostname_idempotent(const char *s);