util.h revision fa776d8e962da9d90459e2f3e86a2a0c6366ee12
/*-*- Mode: C; c-basic-offset: 8 -*-*/
#ifndef fooutilhfoo
#define fooutilhfoo
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <inttypes.h>
#include <time.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
#include <limits.h>
#include "macro.h"
typedef struct dual_timestamp {
#define MSEC_PER_SEC 1000ULL
#define USEC_PER_SEC 1000000ULL
#define USEC_PER_MSEC 1000ULL
#define NSEC_PER_SEC 1000000000ULL
#define NSEC_PER_MSEC 1000000ULL
#define NSEC_PER_USEC 1000ULL
/* What is interpreted as whitespace? */
#define WHITESPACE " \t\n\r"
#define NEWLINE "\n\r"
#define FORMAT_TIMESTAMP_MAX 64
#define FORMAT_TIMESPAN_MAX 64
#define ANSI_HIGHLIGHT_ON "\x1B[1;31m"
#define ANSI_HIGHLIGHT_OFF "\x1B[0m"
bool streq_ptr(const char *a, const char *b);
static inline const char* yes_no(bool b) {
return b ? "yes" : "no";
}
static inline const char* strempty(const char *s) {
return s ? s : "";
}
static inline const char* strnull(const char *s) {
return s ? s : "(null)";
}
static inline const char *strna(const char *s) {
return s ? s : "n/a";
}
static inline bool is_path_absolute(const char *p) {
return *p == '/';
}
bool startswith(const char *s, const char *prefix);
bool startswith_no_case(const char *s, const char *prefix);
bool first_word(const char *s, const char *word);
int close_nointr(int fd);
void close_nointr_nofail(int fd);
int parse_boolean(const char *v);
int safe_atollu(const char *s, unsigned long long *ret_u);
int safe_atolli(const char *s, long long int *ret_i);
#if __WORDSIZE == 32
static inline int safe_atolu(const char *s, unsigned long *ret_u) {
assert_cc(sizeof(unsigned long) == sizeof(unsigned));
}
static inline int safe_atoli(const char *s, long int *ret_u) {
assert_cc(sizeof(long int) == sizeof(int));
}
#else
static inline int safe_atolu(const char *s, unsigned long *ret_u) {
assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
return safe_atollu(s, (unsigned long long*) ret_u);
}
static inline int safe_atoli(const char *s, long int *ret_u) {
assert_cc(sizeof(long int) == sizeof(long long int));
return safe_atolli(s, (long long int*) ret_u);
}
#endif
}
}
return safe_atollu(s, (unsigned long long*) ret_u);
}
return safe_atolli(s, (long long int*) ret_i);
}
for ((state) = NULL, (word) = split((s), &(length), WHITESPACE, &(state)); (word); (word) = split((s), &(length), WHITESPACE, &(state)))
for ((state) = NULL, (word) = split((s), &(length), (separator), &(state)); (word); (word) = split((s), &(length), (separator), &(state)))
for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state)))
char **split_path_and_make_absolute(const char *p);
int readlink_malloc(const char *p, char **r);
int readlink_and_make_absolute(const char *p, char **r);
char *file_name_from_path(const char *p);
bool is_path(const char *p);
bool path_is_absolute(const char *p);
char *path_make_absolute(const char *p, const char *prefix);
char *path_make_absolute_cwd(const char *p);
char **strv_path_make_absolute_cwd(char **l);
char **strv_path_canonicalize(char **l);
int reset_all_signal_handlers(void);
char *strstrip(char *s);
char *delete_chars(char *s, const char *bad);
char *truncate_nl(char *s);
char hexchar(int x);
int unhexchar(char c);
char octchar(int x);
int unoctchar(char c);
char decchar(int x);
int undecchar(char c);
char *cescape(const char *s);
char *cunescape(const char *s);
char *bus_path_escape(const char *s);
char *bus_path_unescape(const char *s);
char *path_kill_slashes(char *path);
bool path_equal(const char *a, const char *b);
char *ascii_strlower(char *path);
bool ignore_file(const char *filename);
bool chars_intersect(const char *a, const char *b);
int make_stdio(int fd);
unsigned long long random_ull(void);
return NULL; \
} \
type i; \
unsigned u = 0; \
assert(s); \
return i; \
if (safe_atou(s, &u) >= 0 && \
return (type) u; \
return (type) -1; \
} \
bool fstype_is_network(const char *fstype);
int reset_terminal(int fd);
int release_terminal(void);
int ignore_signals(int sig, ...);
int default_signals(int sig, ...);
int close_pipe(int p[]);
int path_is_mount_point(const char *path);
bool is_device_path(const char *path);
int dir_is_empty(const char *path);
char* gethostname_malloc(void);
char* getlogname_malloc(void);
int getttyname_malloc(char **r);
int getmachineid_malloc(char **r);
void status_printf(const char *format, ...);
void status_welcome(void);
int columns(void);
const char *ioprio_class_to_string(int i);
int ioprio_class_from_string(const char *s);
const char *sigchld_code_to_string(int i);
int sigchld_code_from_string(const char *s);
const char *log_facility_to_string(int i);
int log_facility_from_string(const char *s);
const char *log_level_to_string(int i);
int log_level_from_string(const char *s);
const char *sched_policy_to_string(int i);
int sched_policy_from_string(const char *s);
const char *rlimit_to_string(int i);
int rlimit_from_string(const char *s);
const char *ip_tos_to_string(int i);
int ip_tos_from_string(const char *s);
#endif