util.h revision 6282c859bdc6463cb25734dcfd3cf8628d951088
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering This file is part of systemd.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Copyright 2010 Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering (at your option) any later version.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is distributed in the hope that it will be useful, but
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Lesser General Public License for more details.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering uint8_t storage[offsetof(struct dirent, d_name) +
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/* What is interpreted as whitespace? */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
4f10118016f9b2fd7e1d26c9ef7d91eb33fba694Lennart Poettering#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool streq_ptr(const char *a, const char *b);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define new0(t, n) ((t*) calloc((n), sizeof(t)))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n)))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic inline const char* yes_no(bool b) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic inline const char* strempty(const char *s) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return s ? s : "";
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic inline const char* strnull(const char *s) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return s ? s : "(null)";
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline const char *strna(const char *s) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return s ? s : "n/a";
a1e58e8ee1c84b633d6d6d651d5328d4dd4eba5bLennart Poetteringstatic inline bool isempty(const char *p) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return !p || !p[0];
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *endswith(const char *s, const char *postfix);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *startswith(const char *s, const char *prefix);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *startswith_no_case(const char *s, const char *prefix);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool first_word(const char *s, const char *word);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringvoid close_many(const int fds[], unsigned n_fd);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint parse_boolean(const char *v);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint parse_bytes(const char *t, off_t *bytes);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint parse_pid(const char *s, pid_t* ret_pid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint parse_uid(const char *s, uid_t* ret_uid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering#define parse_gid(s, ret_uid) parse_uid(s, ret_uid)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint safe_atou(const char *s, unsigned *ret_u);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint safe_atollu(const char *s, unsigned long long *ret_u);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint safe_atolli(const char *s, long long int *ret_i);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint safe_atod(const char *s, double *ret_d);
920b52e4909d9dc812817fd8b82f83ca23a11c91Thomas Hindoe Paaboel Andersenstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned));
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_cc(sizeof(long int) == sizeof(int));
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersenstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen return safe_atollu(s, (unsigned long long*) ret_u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_cc(sizeof(long int) == sizeof(long long int));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return safe_atolli(s, (long long int*) ret_u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(unsigned));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_cc(sizeof(int64_t) == sizeof(long long int));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return safe_atolli(s, (long long int*) ret_i);
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poetteringchar *split(const char *c, size_t *l, const char *separator, char **state);
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poetteringchar *split_quoted(const char *c, size_t *l, char **state);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define FOREACH_WORD(word, length, s, state) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for ((state) = NULL, (word) = split((s), &(length), WHITESPACE, &(state)); (word); (word) = split((s), &(length), WHITESPACE, &(state)))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for ((state) = NULL, (word) = split((s), &(length), (separator), &(state)); (word); (word) = split((s), &(length), (separator), &(state)))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define FOREACH_WORD_QUOTED(word, length, s, state) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state)))
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint get_starttime_of_pid(pid_t pid, unsigned long long *st);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackchar *strappend(const char *s, const char *suffix);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackchar *strnappend(const char *s, const char *suffix, size_t length);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackchar *replace_env(const char *format, char **env);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackchar **replace_env_argv(char **argv, char **env);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint readlink_malloc(const char *p, char **r);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint readlink_and_make_absolute(const char *p, char **r);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint readlink_and_canonicalize(const char *p, char **r);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *delete_chars(char *s, const char *bad);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *file_in_same_dir(const char *path, const char *filename);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint rmdir_parents(const char *path, const char *stop);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint get_process_comm(pid_t pid, char **name);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint get_process_exe(pid_t pid, char **name);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint get_process_uid(pid_t pid, uid_t *uid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint get_process_gid(pid_t pid, gid_t *gid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *cescape(const char *s);
63c372cb9df3bee01e3bf8cd7f96f336bddda846Lennart Poetteringchar *cunescape(const char *s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *cunescape_length(const char *s, size_t length);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poetteringchar *cunescape_length_with_prefix(const char *s, size_t length, const char *prefix);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *xescape(const char *s, const char *bad);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *bus_path_escape(const char *s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *bus_path_unescape(const char *s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringbool dirent_is_file(const struct dirent *de);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringbool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringbool chars_intersect(const char *a, const char *b);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringunsigned long long random_ull(void);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/* For basic lookup tables with strictly enumerated entries */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering scope const char *name##_to_string(type i) { \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering scope type name##_from_string(const char *s) { \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack struct __useless_struct_to_allow_trailing_semicolon__
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) __DEFINE_STRING_TABLE_LOOKUP(name,type,static)
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack/* For string conversions where numbers are also acceptable */
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int name##_to_string_alloc(type i, char **str) { \
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (i < 0 || i > max) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (i < (type) ELEMENTSOF(name##_table)) { \
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering type name##_from_string(const char *s) { \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unsigned u = 0; \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poetteringint close_all_fds(const int except[], unsigned n_except);
cfa9677bd164574600d29a9bf99f9d1f28a7a170Mantas MikulÄ—nasbool fstype_is_network(const char *fstype);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poetteringint ask(char *ret, const char *replies, const char *text, ...);
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poetteringint reset_terminal_fd(int fd, bool switch_to_text);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint open_terminal(const char *name, int mode);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint sigaction_many(const struct sigaction *sa, ...);
b2c23da8cea1987a1a329f5a964d3299b7ca7890Lennart Poetteringint fopen_temporary(const char *path, FILE **_f, char **_temp_path);
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidtssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poetteringssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint get_ctty(pid_t, dev_t *_devnr, char **r);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint rm_rf_dangerous(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringcpu_set_t* cpu_set_malloc(unsigned *ncpus);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringunsigned lines(void);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringvoid columns_lines_cache_reset(int _unused_ signum);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *ellipsize(const char *s, size_t length, unsigned percent);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigned percent);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *unquote(const char *s, const char *quotes);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *normalize_env_assignment(const char *s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint wait_for_terminate(pid_t pid, siginfo_t *status);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint wait_for_terminate_and_warn(const char *name, pid_t pid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart PoetteringDIR *xopendirat(int dirfd, const char *name, int flags);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *fstab_node_to_udev_node(const char *p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringconst char *default_term_for_tty(const char *tty);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringvoid execute_directory(const char *directory, DIR *_d, char *argv[]);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool nulstr_contains(const char*nulstr, const char *needle);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool hostname_is_valid(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint copy_file(const char *from, const char *to);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint symlink_atomic(const char *from, const char *to);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool display_is_local(const char *display);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint socket_from_display(const char *display, char **path);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidtint get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint get_group_creds(const char **groupname, gid_t *gid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint dirent_ensure_type(DIR *d, struct dirent *de);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint in_search_path(const char *path, char **search);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint get_files_in_directory(const char *path, char ***list);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *strjoin(const char *x, ...) _sentinel_;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringbool in_charset(const char *s, const char* charset);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint block_get_whole_disk(dev_t d, dev_t *ret);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint file_is_priv_sticky(const char *p);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint strdup_or_null(const char *a, char **b);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint ioprio_class_to_string_alloc(int i, char **s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint ioprio_class_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringconst char *sigchld_code_to_string(int i);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint sigchld_code_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint log_facility_unshifted_to_string_alloc(int i, char **s);
db2cb23b5b179707000d28a11efb3d888d06ee80Umut Tezduyar Lindskogint log_facility_unshifted_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint log_level_to_string_alloc(int i, char **s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint log_level_from_string(const char *s);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poetteringint sched_policy_to_string_alloc(int i, char **s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringint sched_policy_from_string(const char *s);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringconst char *rlimit_to_string(int i);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint rlimit_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint ip_tos_to_string_alloc(int i, char **s);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poetteringint ip_tos_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringconst char *signal_to_string(int i);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint signal_from_string(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint signal_from_string_try_harder(const char *s);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringchar *format_bytes(char *buf, size_t l, off_t t);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringint fd_wait_for_event(int fd, int event, usec_t timeout);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringvoid* memdup(const void *p, size_t l) _malloc_;
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint setrlimit_closest(int resource, const struct rlimit *rlim);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackint getenv_for_pid(pid_t pid, const char *field, char **_value);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool is_valid_documentation_url(const char *url);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic inline void freep(void *p) {
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return malloc(a * b);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering_malloc_ static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering return memdup(p, a * b);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool filename_is_safe(const char *p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool path_is_safe(const char *p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool string_is_safe(const char *p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringbool string_has_cc(const char *p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringvoid *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int (*compar) (const void *, const void *, void *),
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackconst char *draw_special_char(DrawSpecialChar ch);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mackchar *strreplace(const char *text, const char *old_string, const char *new_string);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringchar *strip_tab_ansi(char **p, size_t *l);
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poetteringint search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f);
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poetteringint search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic inline void *mempset(void *s, int c, size_t n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return (char*)s + n;