util.h revision 059cb3858acd038ff2cef10a3a99119bf71a8fc6
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering This file is part of systemd.
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering Copyright 2010 Lennart Poettering
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering systemd is free software; you can redistribute it and/or modify it
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering under the terms of the GNU Lesser General Public License as published by
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering (at your option) any later version.
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering systemd is distributed in the hope that it will be useful, but
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering Lesser General Public License for more details.
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering You should have received a copy of the GNU Lesser General Public License
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering/* What is interpreted as whitespace? */
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m"
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringbool streq_ptr(const char *a, const char *b) _pure_;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#define new0(t, n) ((t*) calloc((n), sizeof(t)))
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n)))
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline const char* yes_no(bool b) {
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringstatic inline const char* true_false(bool b) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline const char* strempty(const char *s) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering return s ? s : "";
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline const char* strnull(const char *s) {
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering return s ? s : "(null)";
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidtstatic inline const char *strna(const char *s) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering return s ? s : "n/a";
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline bool isempty(const char *p) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering return !p || !p[0];
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline const char *startswith(const char *s, const char *prefix) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering if (strncmp(s, prefix, strlen(prefix)) == 0)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline const char *startswith_no_case(const char *s, const char *prefix) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering if (strncasecmp(s, prefix, strlen(prefix)) == 0)
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringchar *endswith(const char *s, const char *postfix) _pure_;
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringbool first_word(const char *s, const char *word) _pure_;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringvoid close_many(const int fds[], unsigned n_fd);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint parse_size(const char *t, off_t base, off_t *size);
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringint parse_pid(const char *s, pid_t* ret_pid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint parse_uid(const char *s, uid_t* ret_uid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define parse_gid(s, ret_uid) parse_uid(s, ret_uid)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint safe_atou(const char *s, unsigned *ret_u);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint safe_atollu(const char *s, unsigned long long *ret_u);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint safe_atolli(const char *s, long long int *ret_i);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint safe_atod(const char *s, double *ret_d);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned));
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering assert_cc(sizeof(long int) == sizeof(int));
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering assert_cc(sizeof(long int) == sizeof(long long int));
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering return safe_atolli(s, (long long int*) ret_u);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt assert_cc(sizeof(uint32_t) == sizeof(unsigned));
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering assert_cc(sizeof(int64_t) == sizeof(long long int));
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering return safe_atolli(s, (long long int*) ret_i);
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidtchar *split(const char *c, size_t *l, const char *separator, bool quoted, char **state);
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering#define FOREACH_WORD(word, length, s, state) \
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering _FOREACH_WORD(word, length, s, WHITESPACE, false, state)
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering _FOREACH_WORD(word, length, s, separator, false, state)
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering#define FOREACH_WORD_QUOTED(word, length, s, state) \
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering _FOREACH_WORD(word, length, s, WHITESPACE, true, state)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define FOREACH_WORD_SEPARATOR_QUOTED(word, length, s, separator, state) \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering _FOREACH_WORD(word, length, s, separator, true, state)
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering for ((state) = NULL, (word) = split((s), &(length), (separator), (quoted), &(state)); (word); (word) = split((s), &(length), (separator), (quoted), &(state)))
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringpid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_starttime_of_pid(pid_t pid, unsigned long long *st);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *strappend(const char *s, const char *suffix);
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringchar *strnappend(const char *s, const char *suffix, size_t length);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *replace_env(const char *format, char **env);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar **replace_env_argv(char **argv, char **env);
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poetteringint readlink_malloc(const char *p, char **r);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint readlink_and_make_absolute(const char *p, char **r);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint readlink_and_canonicalize(const char *p, char **r);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *delete_chars(char *s, const char *bad);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *file_in_same_dir(const char *path, const char *filename);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint rmdir_parents(const char *path, const char *stop);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint get_process_comm(pid_t pid, char **name);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_process_exe(pid_t pid, char **name);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint get_process_uid(pid_t pid, uid_t *uid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_process_gid(pid_t pid, gid_t *gid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_process_capeff(pid_t pid, char **capeff);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *cescape(const char *s);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringchar *cunescape(const char *s);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *cunescape_length(const char *s, size_t length);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringchar *xescape(const char *s, const char *bad);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringbool dirent_is_file(const struct dirent *de) _pure_;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringbool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringbool ignore_file(const char *filename) _pure_;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringbool chars_intersect(const char *a, const char *b) _pure_;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering/* For basic lookup tables with strictly enumerated entries */
4ba93280223ceb5de1bcedb196c38252f334521aLennart Poettering#define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering scope const char *name##_to_string(type i) { \
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poettering if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poettering scope type name##_from_string(const char *s) { \
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,)
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,static)
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering/* For string conversions where numbers are also acceptable */
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering int name##_to_string_alloc(type i, char **str) { \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering if (i < 0 || i > max) \
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poettering if (i < (type) ELEMENTSOF(name##_table)) { \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering type name##_from_string(const char *s) { \
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering unsigned u = 0; \
eaf73b061604c028aa28f960870a9b46aab2f76aLuke Shumaker for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
90d14d2015dda79c7b465b74dd3aaf2dfc25d43cLuke Shumaker struct __useless_struct_to_allow_trailing_semicolon__
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringint close_all_fds(const int except[], unsigned n_except);
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringbool fstype_is_network(const char *fstype);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringint ask(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringint reset_terminal_fd(int fd, bool switch_to_text);
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringint open_terminal(const char *name, int mode);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint sigaction_many(const struct sigaction *sa, ...);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint fopen_temporary(const char *path, FILE **_f, char **_temp_path);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
9c857b9d160c10b4454fc9f83442c1878343422fLennart Poetteringssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint get_ctty(pid_t, dev_t *_devnr, char **r);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint rm_rf_dangerous(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
d60473c7ba32f2325a13f0357b23fd8e25609650Lennart Poetteringcpu_set_t* cpu_set_malloc(unsigned *ncpus);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringint status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringint status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poetteringunsigned lines(void);
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poetteringvoid columns_lines_cache_reset(int _unused_ signum);
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poetteringstatic inline const char *ansi_highlight(void) {
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering return on_tty() ? ANSI_HIGHLIGHT_ON : "";
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poetteringstatic inline const char *ansi_highlight_red(void) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poetteringstatic inline const char *ansi_highlight_green(void) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poetteringstatic inline const char *ansi_highlight_yellow(void) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : "";
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poetteringstatic inline const char *ansi_highlight_blue(void) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : "";
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poetteringstatic inline const char *ansi_highlight_off(void) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poetteringchar *ellipsize(const char *s, size_t length, unsigned percent);
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering /* bytes columns */
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poetteringchar *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent);
char *normalize_env_assignment(const char *s);
char *fstab_node_to_udev_node(const char *p);
bool plymouth_running(void);
int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
bool is_main_thread(void);
int file_is_priv_sticky(const char *p);
int strdup_or_null(const char *a, char **b);
#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 log_facility_unshifted_to_string_alloc(int i, char **s);
int log_facility_unshifted_from_string(const char *s);
int log_level_to_string_alloc(int i, char **s);
int log_level_from_string(const char *s);
int sched_policy_to_string_alloc(int i, char **s);
int sched_policy_from_string(const char *s);
int ip_tos_to_string_alloc(int i, char **s);
int ip_tos_from_string(const char *s);
int signal_from_string_try_harder(const char *s);
extern int saved_argc;
extern char **saved_argv;
bool kexec_loaded(void);
bool in_initrd(void);
void warn_melody(void);
static inline void freep(void *p) {
free(*(void**) p);
func(*p); \
if (*fd >= 0)
umask(*u);
close_pipe(*p);
return NULL;
return malloc(a * b);
return NULL;
return memdup(p, a * b);
int (*compar) (const void *, const void *, void *),
void *arg);
bool is_locale_utf8(void);
typedef enum DrawSpecialChar {
int on_ac_power(void);
if (ferror(f)) { \
on_error; \
if (!de) { \
if (errno > 0) { \
on_error; \
memset(s, c, n);
return (uint8_t*)s + n;
char *strrep(const char *s, unsigned n);
if (_ptr) \
_ptr; \
struct _umask_struct_ {
bool quit;
return __builtin_ctz(n);
static inline bool logind_running(void) {
#define DECIMAL_STR_WIDTH(x) \
ans++; \
ans; \
#define alloca0(n) \
char *_new_; \
#define strappenda(a, b) \
char *_c_; \
_c_; \
const char *_r_; \
if (_pid_ == 0) { \
_r_; \
struct _locale_struct_ {
bool quit;
for (_cleanup_(_reset_locale_) struct _locale_struct_ _saved_locale_ = { (locale_t) 0, (locale_t) 0, false }; \
int shall_restore_state(void);
int (*compar)(const void *, const void *)) {
if (nmemb) {
unsigned long personality_from_string(const char *p);
const char *personality_to_string(unsigned long);