]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/util.h
meson: make user $PATH configurable
[thirdparty/systemd.git] / src / basic / util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
60918275 3
11c3a366 4#include <stdint.h>
ca78ad1d 5
a838e6a1 6#include "macro.h"
871d7de4 7
9a0e6896
LP
8extern int saved_argc;
9extern char **saved_argv;
10
36fea155
LP
11static inline void save_argc_argv(int argc, char **argv) {
12 saved_argc = argc;
13 saved_argv = argv;
14}
15
65457142
FC
16bool kexec_loaded(void);
17
44a6b1b6 18int prot_from_flags(int flags) _const_;
87d2c1ff 19
9be346c9 20bool in_initrd(void);
dcd61450 21void in_initrd_force(bool value);
069cfc85 22
b5efdb8a
LP
23int on_ac_power(void);
24
144e51ec 25static inline unsigned u64log2(uint64_t n) {
ec417ccc 26#if __SIZEOF_LONG_LONG__ == 8
693eb9a2 27 return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;
ec417ccc
LP
28#else
29#error "Wut?"
30#endif
31}
32
33static inline unsigned u32ctz(uint32_t n) {
34#if __SIZEOF_INT__ == 4
1a359852 35 return n != 0 ? __builtin_ctz(n) : 32;
ec417ccc
LP
36#else
37#error "Wut?"
38#endif
144e51ec 39}
79d860fe 40
7d328b54 41static inline unsigned log2i(int x) {
8fe90522
ZJS
42 assert(x > 0);
43
44 return __SIZEOF_INT__ * 8 - __builtin_clz(x) - 1;
45}
46
b5de6d98
MS
47static inline unsigned log2u(unsigned x) {
48 assert(x > 0);
49
50 return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
51}
52
53static inline unsigned log2u_round_up(unsigned x) {
54 assert(x > 0);
55
56 if (x == 1)
57 return 0;
58
59 return log2u(x - 1) + 1;
60}
61
bc9fd78c
LP
62int container_get_leader(const char *machine, pid_t *pid);
63
3f6fd1ba 64int version(void);
68c58c67
LP
65
66int str_verscmp(const char *s1, const char *s2);
9ce17593 67
e557b1a6 68void disable_coredumps(void);