X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=3e89aaf17fe2a1e9640a355c4a7c084a921c9436;hb=75cd513ef830d8e00d0d2d6a64917fec533315db;hp=8544940eabdb17743d0aafa23421798065854350;hpb=6294aa76d818e831de4592b41a37e225fd0871f9;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 8544940ea..3e89aaf17 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -84,6 +84,7 @@ #endif #include "macro.h" +#include "missing.h" #include "time-util.h" /* What is interpreted as whitespace? */ @@ -93,6 +94,12 @@ #define COMMENTS "#;" #define GLOB_CHARS "*?[" +/* What characters are special in the shell? */ +/* must be escaped outside and inside double-quotes */ +#define SHELL_NEED_ESCAPE "\"\\`$" +/* can be escaped or double-quoted */ +#define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;" + #define FORMAT_BYTES_MAX 8 #define ANSI_HIGHLIGHT_ON "\x1B[1;39m" @@ -163,7 +170,7 @@ static inline const char *startswith_no_case(const char *s, const char *prefix) char *endswith(const char *s, const char *postfix) _pure_; -bool first_word(const char *s, const char *word) _pure_; +char *first_word(const char *s, const char *word) _pure_; int close_nointr(int fd); int safe_close(int fd); @@ -186,6 +193,8 @@ int safe_atolli(const char *s, long long int *ret_i); int safe_atod(const char *s, double *ret_d); +int safe_atou8(const char *s, uint8_t *ret); + #if __WORDSIZE == 32 static inline int safe_atolu(const char *s, unsigned long *ret_u) { assert_cc(sizeof(unsigned long) == sizeof(unsigned)); @@ -226,7 +235,7 @@ static inline int safe_atoi64(const char *s, int64_t *ret_i) { return safe_atolli(s, (long long int*) ret_i); } -char *split(const char *c, size_t *l, const char *separator, bool quoted, char **state); +const char* split(const char **state, size_t *l, const char *separator, bool quoted); #define FOREACH_WORD(word, length, s, state) \ _FOREACH_WORD(word, length, s, WHITESPACE, false, state) @@ -241,7 +250,7 @@ char *split(const char *c, size_t *l, const char *separator, bool quoted, char * _FOREACH_WORD(word, length, s, separator, true, state) #define _FOREACH_WORD(word, length, s, separator, quoted, state) \ - for ((state) = NULL, (word) = split((s), &(length), (separator), (quoted), &(state)); (word); (word) = split((s), &(length), (separator), (quoted), &(state))) + for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted))) pid_t get_parent_of_pid(pid_t pid, pid_t *ppid); int get_starttime_of_pid(pid_t pid, unsigned long long *st); @@ -493,6 +502,7 @@ noreturn void freeze(void); bool null_or_empty(struct stat *st) _pure_; int null_or_empty_path(const char *fn); +int null_or_empty_fd(int fd); DIR *xopendirat(int dirfd, const char *name, int flags); @@ -964,3 +974,5 @@ char *tempfn_xxxxxx(const char *p); char *tempfn_random(const char *p); bool is_localhost(const char *hostname); + +int take_password_lock(const char *root);