util.h revision 7ccbd1ae843d77275f2c542582a9a80e5e058a70
f370eece69b53591e104fab667134cfe8d96fabdNathaniel McCallum/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f370eece69b53591e104fab667134cfe8d96fabdNathaniel McCallum This file is part of systemd.
f370eece69b53591e104fab667134cfe8d96fabdNathaniel McCallum Copyright 2010 Lennart Poettering
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <alloca.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "formats-util.h"
#include "macro.h"
#include "missing.h"
#include "time-util.h"
return NULL;
static inline const char* yes_no(bool b) {
static inline const char* true_false(bool b) {
static inline const char* one_zero(bool b) {
bool plymouth_running(void);
#define NULSTR_FOREACH(i, l) \
#define NULSTR_FOREACH_PAIR(i, j, l) \
for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
int ioprio_class_to_string_alloc(int i, char **s);
int ioprio_class_from_string(const char *s);
int sched_policy_to_string_alloc(int i, char **s);
int sched_policy_from_string(const char *s);
extern int saved_argc;
extern char **saved_argv;
bool kexec_loaded(void);
bool in_initrd(void);
static inline void freep(void *p) {
free(*(void**) p);
return NULL;
return malloc(a * b);
return NULL;
return realloc(p, a * b);
return NULL;
return memdup(p, a * b);
int (*compar) (const void *, const void *, void *),
void *arg);
int on_ac_power(void);
memset(s, c, n);
return (uint8_t*)s + n;
static inline int negative_errno(void) {
return -errno;
return __builtin_ctz(n);
static inline unsigned log2i(int x) {
assert(x > 0);
static inline unsigned log2u(unsigned x) {
assert(x > 0);
static inline unsigned log2u_round_up(unsigned x) {
assert(x > 0);
#define DECIMAL_STR_WIDTH(x) \
ans++; \
ans; \
#define alloca0(n) \
char *_new_; \
/* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */
void *_ptr_; \
void *_new_; \
int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
#ifndef PERSONALITY_INVALID
unsigned long personality_from_string(const char *p);
const char *personality_to_string(unsigned long);
union file_handle_union {
union inotify_event_buffer {
int version(void);
bool fdname_is_valid(const char *s);