util.h revision 830964834f330836b9d33752e83de09d4f38da87
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
220a21d38f675eb835f5758e3d23e896573aa5eaLennart Poettering
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt#ifndef fooutilhfoo
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt#define fooutilhfoo
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering/***
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering This file is part of systemd.
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering Copyright 2010 Lennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering systemd is free software; you can redistribute it and/or modify it
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering under the terms of the GNU General Public License as published by
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering the Free Software Foundation; either version 2 of the License, or
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering (at your option) any later version.
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering systemd is distributed in the hope that it will be useful, but
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering General Public License for more details.
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering You should have received a copy of the GNU General Public License
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt along with systemd; If not, see <http://www.gnu.org/licenses/>.
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt***/
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <inttypes.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <time.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <sys/time.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <stdarg.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <stdbool.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <stdlib.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <stdio.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <signal.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <sched.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include <limits.h>
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt#include <sys/stat.h>
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt#include <dirent.h>
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#include "macro.h"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringtypedef uint64_t usec_t;
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringtypedef struct dual_timestamp {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering usec_t realtime;
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering usec_t monotonic;
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering} dual_timestamp;
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define MSEC_PER_SEC 1000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_SEC 1000000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_MSEC 1000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define NSEC_PER_SEC 1000000000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define NSEC_PER_MSEC 1000000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define NSEC_PER_USEC 1000ULL
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_MINUTE (60ULL*USEC_PER_SEC)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_HOUR (60ULL*USEC_PER_MINUTE)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_DAY (24ULL*USEC_PER_HOUR)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_WEEK (7ULL*USEC_PER_DAY)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_MONTH (2629800ULL*USEC_PER_SEC)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define USEC_PER_YEAR (31557600ULL*USEC_PER_SEC)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering/* What is interpreted as whitespace? */
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define WHITESPACE " \t\n\r"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define NEWLINE "\n\r"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define QUOTES "\"\'"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define COMMENTS "#;\n"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define FORMAT_TIMESTAMP_MAX 64
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define FORMAT_TIMESTAMP_PRETTY_MAX 256
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define FORMAT_TIMESPAN_MAX 64
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define ANSI_HIGHLIGHT_ON "\x1B[1;31m"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define ANSI_HIGHLIGHT_OFF "\x1B[0m"
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringusec_t now(clockid_t clock);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittdual_timestamp* dual_timestamp_get(dual_timestamp *ts);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittdual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt#define dual_timestamp_is_set(ts) ((ts)->realtime > 0)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringusec_t timespec_load(const struct timespec *ts);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittstruct timespec *timespec_store(struct timespec *ts, usec_t u);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittusec_t timeval_load(const struct timeval *tv);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittstruct timeval *timeval_store(struct timeval *tv, usec_t u);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittsize_t page_size(void);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define streq(a,b) (strcmp((a),(b)) == 0)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringbool streq_ptr(const char *a, const char *b);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define new(t, n) ((t*) malloc(sizeof(t)*(n)))
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define new0(t, n) ((t*) calloc((n), sizeof(t)))
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#define malloc0(n) (calloc((n), 1))
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringstatic inline const char* yes_no(bool b) {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return b ? "yes" : "no";
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt}
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittstatic inline const char* strempty(const char *s) {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return s ? s : "";
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering}
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringstatic inline const char* strnull(const char *s) {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return s ? s : "(null)";
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt}
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringstatic inline const char *strna(const char *s) {
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt return s ? s : "n/a";
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt}
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringstatic inline bool is_path_absolute(const char *p) {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return *p == '/';
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering}
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittstatic inline bool isempty(const char *p) {
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt return !p || !p[0];
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt}
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringbool endswith(const char *s, const char *postfix);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittbool startswith(const char *s, const char *prefix);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pittbool startswith_no_case(const char *s, const char *prefix);
8968aea0fb900b5b786eea51a316652fce5641f8Martin Pitt
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringbool first_word(const char *s, const char *word);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint close_nointr(int fd);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringvoid close_nointr_nofail(int fd);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringvoid close_many(const int fds[], unsigned n_fd);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint parse_boolean(const char *v);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint parse_usec(const char *t, usec_t *usec);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint parse_pid(const char *s, pid_t* ret_pid);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint safe_atou(const char *s, unsigned *ret_u);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint safe_atoi(const char *s, int *ret_i);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint safe_atollu(const char *s, unsigned long long *ret_u);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringint safe_atolli(const char *s, long long int *ret_i);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering#if __WORDSIZE == 32
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poetteringstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering assert_cc(sizeof(unsigned long) == sizeof(unsigned));
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return safe_atou(s, (unsigned*) ret_u);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering}
61f32bff6130a44d077886d38cff89ad161bf177Martin Pittstatic inline int safe_atoli(const char *s, long int *ret_u) {
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt assert_cc(sizeof(long int) == sizeof(int));
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering return safe_atoi(s, (int*) ret_u);
d5f8b2952a9c24c41f82fc3a12c1b580424566cbLennart Poettering}
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt#else
61f32bff6130a44d077886d38cff89ad161bf177Martin Pittstatic inline int safe_atolu(const char *s, unsigned long *ret_u) {
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt assert_cc(sizeof(unsigned long) == sizeof(unsigned long long));
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt return safe_atollu(s, (unsigned long long*) ret_u);
61f32bff6130a44d077886d38cff89ad161bf177Martin Pitt}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringstatic inline int safe_atoli(const char *s, long int *ret_u) {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering assert_cc(sizeof(long int) == sizeof(long long int));
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering return safe_atolli(s, (long long int*) ret_u);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#endif
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringstatic inline int safe_atou32(const char *s, uint32_t *ret_u) {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(unsigned));
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering return safe_atou(s, (unsigned*) ret_u);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringstatic inline int safe_atoi32(const char *s, int32_t *ret_i) {
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering return safe_atoi(s, (int*) ret_i);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringstatic inline int safe_atou64(const char *s, uint64_t *ret_u) {
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering assert_cc(sizeof(uint64_t) == sizeof(unsigned long long));
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering return safe_atollu(s, (unsigned long long*) ret_u);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringstatic inline int safe_atoi64(const char *s, int64_t *ret_i) {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering assert_cc(sizeof(int64_t) == sizeof(long long int));
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering return safe_atolli(s, (long long int*) ret_i);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering}
815bb5bd565b4edc05a426d24353a9ba68482834Thomas Hindoe Paaboel Andersen
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *split(const char *c, size_t *l, const char *separator, char **state);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *split_quoted(const char *c, size_t *l, char **state);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering#define FOREACH_WORD(word, length, s, state) \
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering for ((state) = NULL, (word) = split((s), &(length), WHITESPACE, &(state)); (word); (word) = split((s), &(length), WHITESPACE, &(state)))
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering for ((state) = NULL, (word) = split((s), &(length), (separator), &(state)); (word); (word) = split((s), &(length), (separator), &(state)))
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#define FOREACH_WORD_QUOTED(word, length, s, state) \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state)))
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar **split_path_and_make_absolute(const char *p);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringpid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint get_starttime_of_pid(pid_t pid, unsigned long long *st);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint write_one_line_file(const char *fn, const char *line);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint write_one_line_file_atomic(const char *fn, const char *line);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint read_one_line_file(const char *fn, char **line);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint read_full_file(const char *fn, char **contents, size_t *size);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint load_env_file(const char *fname, char ***l);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint write_env_file(const char *fname, char **l);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *strappend(const char *s, const char *suffix);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *strnappend(const char *s, const char *suffix, size_t length);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *replace_env(const char *format, char **env);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar **replace_env_argv(char **argv, char **env);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint readlink_malloc(const char *p, char **r);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint readlink_and_make_absolute(const char *p, char **r);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint readlink_and_canonicalize(const char *p, char **r);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *file_name_from_path(const char *p);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringbool is_path(const char *p);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringbool path_is_absolute(const char *p);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *path_make_absolute(const char *p, const char *prefix);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *path_make_absolute_cwd(const char *p);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar **strv_path_make_absolute_cwd(char **l);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar **strv_path_canonicalize(char **l);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar **strv_path_remove_empty(char **l);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint reset_all_signal_handlers(void);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *strstrip(char *s);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *delete_chars(char *s, const char *bad);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar *truncate_nl(char *s);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *file_in_same_dir(const char *path, const char *filename);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint mkdir_parents(const char *path, mode_t mode);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint mkdir_p(const char *path, mode_t mode);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint parent_of_path(const char *path, char **parent);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint rmdir_parents(const char *path, const char *stop);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringint get_process_name(pid_t pid, char **name);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringint get_process_cmdline(pid_t pid, size_t max_length, char **line);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poettering
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringchar hexchar(int x);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringint unhexchar(char c);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringchar octchar(int x);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringint unoctchar(char c);
ddb4b0d3eb57292c38a76f9b977f73cea15448fbLennart Poetteringchar decchar(int x);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint undecchar(char c);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *cescape(const char *s);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *cunescape(const char *s);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *cunescape_length(const char *s, size_t length);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *xescape(const char *s, const char *bad);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringchar *bus_path_escape(const char *s);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *bus_path_unescape(const char *s);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *path_kill_slashes(char *path);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringbool path_startswith(const char *path, const char *prefix);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringbool path_equal(const char *a, const char *b);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
815bb5bd565b4edc05a426d24353a9ba68482834Thomas Hindoe Paaboel Andersenchar *ascii_strlower(char *path);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringbool dirent_is_file(struct dirent *de);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringbool ignore_file(const char *filename);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringbool chars_intersect(const char *a, const char *b);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
815bb5bd565b4edc05a426d24353a9ba68482834Thomas Hindoe Paaboel Andersenchar *format_timestamp(char *buf, size_t l, usec_t t);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *format_timestamp_pretty(char *buf, size_t l, usec_t t);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringchar *format_timespan(char *buf, size_t l, usec_t t);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint make_stdio(int fd);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint make_null_stdio(void);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringunsigned long long random_ull(void);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#define DEFINE_STRING_TABLE_LOOKUP(name,type) \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering const char *name##_to_string(type i) { \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering return NULL; \
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering return name##_table[i]; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering } \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering type name##_from_string(const char *s) { \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering type i; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering unsigned u = 0; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering assert(s); \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering if (name##_table[i] && \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering streq(name##_table[i], s)) \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering return i; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering if (safe_atou(s, &u) >= 0 && \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering u < ELEMENTSOF(name##_table)) \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering return (type) u; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering return (type) -1; \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering } \
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint fd_nonblock(int fd, bool nonblock);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint fd_cloexec(int fd, bool cloexec);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint close_all_fds(const int except[], unsigned n_except);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringbool fstype_is_network(const char *fstype);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint chvt(int vt);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poettering
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint read_one_char(FILE *f, char *ret, bool *need_nl);
b9e2f7eb00643f28390cedf883f516f4ba7193bbLennart Poetteringint ask(char *ret, const char *replies, const char *text, ...);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint reset_terminal_fd(int fd);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint reset_terminal(const char *name);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint open_terminal(const char *name, int mode);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint release_terminal(void);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint flush_fd(int fd);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint ignore_signals(int sig, ...);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint default_signals(int sig, ...);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint sigaction_many(const struct sigaction *sa, ...);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint close_pipe(int p[]);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint fopen_temporary(const char *path, FILE **_f, char **_temp_path);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint path_is_mount_point(const char *path);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringbool is_device_path(const char *path);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint dir_is_empty(const char *path);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringvoid rename_process(const char name[8]);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringvoid sigset_add_many(sigset_t *ss, ...);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar* gethostname_malloc(void);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringchar* getlogname_malloc(void);
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poettering
f1f8a5a5e110f485257e8702ad30b9997e529a74Lennart Poetteringint getttyname_malloc(int fd, char **r);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringint getttyname_harder(int fd, char **r);
dd050decb6ad131ebdeabb71c4f9ecb4733269c0David Herrmann
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poetteringint get_ctty_devnr(pid_t pid, dev_t *d);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint get_ctty(pid_t, dev_t *_devnr, char **r);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint rm_rf(const char *path, bool only_dirs, bool delete_root);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint pipe_eof(int fd);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackcpu_set_t* cpu_set_malloc(unsigned *ncpus);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackvoid status_vprintf(const char *format, va_list ap);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackvoid status_printf(const char *format, ...);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackvoid status_welcome(void);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint columns(void);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint running_in_chroot(void);
6fd5517b11d2c258b3c09baf571bae71b9ac98a7Zbigniew Jędrzejewski-Szmek
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackchar *ellipsize(const char *s, unsigned length, unsigned percent);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint touch(const char *path);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringchar *unquote(const char *s, const char *quotes);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringchar *normalize_env_assignment(const char *s);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint wait_for_terminate(pid_t pid, siginfo_t *status);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackint wait_for_terminate_and_warn(const char *name, pid_t pid);
6fd5517b11d2c258b3c09baf571bae71b9ac98a7Zbigniew Jędrzejewski-Szmek
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack_noreturn_ void freeze(void);
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mack
c97e586d8a18db5dc505d76059ed1d9add234925Daniel Mackbool null_or_empty(struct stat *st);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackint null_or_empty_path(const char *fn);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel MackDIR *xopendirat(int dirfd, const char *name, int flags);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackvoid dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackvoid dual_timestamp_deserialize(const char *value, dual_timestamp *t);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackchar *fstab_node_to_udev_node(const char *p);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackvoid filter_environ(const char *prefix);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackbool tty_is_vc(const char *tty);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackint vtnr_from_tty(const char *tty);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringconst char *default_term_for_tty(const char *tty);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint detect_vm(const char **id);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint detect_container(const char **id);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackint detect_virtualization(const char **id);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringvoid execute_directory(const char *directory, DIR *_d, char *argv[]);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mackint kill_and_sigcont(pid_t pid, int sig);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringbool nulstr_contains(const char*nulstr, const char *needle);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringbool plymouth_running(void);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringvoid parse_syslog_priority(char **p, int *priority);
21d86c613d85a5ffb23decaf9876b9f42696e718Daniel Mack
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint have_effective_cap(int value);
8b5f9d156ceec7284eeabe79fcbf51f503eb50f5Daniel Mack
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringbool hostname_is_valid(const char *s);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringchar* hostname_cleanup(char *s);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringchar* strshorten(char *s, size_t l);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint terminal_vhangup_fd(int fd);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint terminal_vhangup(const char *name);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint vt_disallocate(const char *name);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint copy_file(const char *from, const char *to);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint symlink_or_copy(const char *from, const char *to);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint symlink_or_copy_atomic(const char *from, const char *to);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint fchmod_umask(int fd, mode_t mode);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint hwclock_is_localtime(void);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint hwclock_apply_localtime_delta(int *min);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint hwclock_reset_localtime_delta(void);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint hwclock_get_time(struct tm *tm);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint hwclock_set_time(const struct tm *tm);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint audit_session_from_pid(pid_t pid, uint32_t *id);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringbool display_is_local(const char *display);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint socket_from_display(const char *display, char **path);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint glob_exists(const char *path);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint dirent_ensure_type(DIR *d, struct dirent *de);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint in_search_path(const char *path, char **search);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering#define NULSTR_FOREACH(i, l) \
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering#define NULSTR_FOREACH_PAIR(i, j, l) \
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackconst char *ioprio_class_to_string(int i);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackint ioprio_class_from_string(const char *s);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackconst char *sigchld_code_to_string(int i);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackint sigchld_code_from_string(const char *s);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringconst char *log_facility_unshifted_to_string(int i);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint log_facility_unshifted_from_string(const char *s);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poettering
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringconst char *log_level_to_string(int i);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackint log_level_from_string(const char *s);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack
a8eaaee72a2f06e0fb64fb71de3b71ecba31dafbJan Engelhardtconst char *sched_policy_to_string(int i);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackint sched_policy_from_string(const char *s);
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mackconst char *rlimit_to_string(int i);
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringint rlimit_from_string(const char *s);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringconst char *ip_tos_to_string(int i);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint ip_tos_from_string(const char *s);
edf4126f60561cc6236e46d07f4845dbc6935fa2Tom Gundersen
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringconst char *signal_to_string(int i);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint signal_from_string(const char *s);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poetteringint signal_from_string_try_harder(const char *s);
d046fb936658e7239c8e2635ecb7fb32748ef535Lennart Poettering
edf4126f60561cc6236e46d07f4845dbc6935fa2Tom Gundersenextern int saved_argc;
fe08a30b58bba0e04fb3e43122e0b157af5846a1Lennart Poetteringextern char **saved_argv;
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack#endif
bdba9227ec6462198b63af69098a003aa2292c0fDaniel Mack