X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=11ab9f6c0b2bce65ea39f272a34086ba999d499d;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=410ce65f14a9d52d20a42bfe701f9f7c1129f6d0;hpb=7d328b544621d4b1bec936dec612947ad8bfb65a;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 410ce65f1..11ab9f6c0 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -25,23 +25,20 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include +#include #include #include -#include #include #include #include #include -#include #include #if SIZEOF_PID_T == 4 @@ -282,9 +279,6 @@ int readlink_value(const char *p, char **ret); int readlink_and_make_absolute(const char *p, char **r); int readlink_and_canonicalize(const char *p, char **r); -int reset_all_signal_handlers(void); -int reset_signal_mask(void); - char *strstrip(char *s); char *delete_chars(char *s, const char *bad); char *truncate_nl(char *s); @@ -355,16 +349,11 @@ static inline uint32_t random_u32(void) { return name##_table[i]; \ } -#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ - scope type name##_from_string(const char *s) { \ - type i; \ - if (!s) \ - return (type) -1; \ - for (i = 0; i < (type)ELEMENTSOF(name##_table); i++) \ - if (name##_table[i] && \ - streq(name##_table[i], s)) \ - return i; \ - return (type) -1; \ +ssize_t string_table_lookup(const char * const *table, size_t len, const char *key); + +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ + scope inline type name##_from_string(const char *s) { \ + return (type)string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ } #define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ @@ -432,13 +421,10 @@ int release_terminal(void); int flush_fd(int fd); -int ignore_signals(int sig, ...); -int default_signals(int sig, ...); -int sigaction_many(const struct sigaction *sa, ...); - int fopen_temporary(const char *path, FILE **_f, char **_temp_path); ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll); +int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll); int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll); bool is_device_path(const char *path); @@ -448,9 +434,6 @@ char* dirname_malloc(const char *path); void rename_process(const char name[8]); -void sigset_add_many(sigset_t *ss, ...); -int sigprocmask_many(int how, ...); - bool hostname_is_set(void); char* lookup_uid(uid_t uid); @@ -633,11 +616,6 @@ int rlimit_from_string(const char *s) _pure_; int ip_tos_to_string_alloc(int i, char **s); int ip_tos_from_string(const char *s); -const char *signal_to_string(int i) _const_; -int signal_from_string(const char *s) _pure_; - -int signal_from_string_try_harder(const char *s); - extern int saved_argc; extern char **saved_argv; @@ -742,6 +720,8 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); +#define _(String) gettext (String) +void init_gettext(void); bool is_locale_utf8(void); typedef enum DrawSpecialChar { @@ -872,16 +852,6 @@ static inline unsigned log2u(unsigned x) { return sizeof(unsigned) * 8 - __builtin_clz(x) - 1; } -static inline unsigned log2u64(uint64_t x) { - assert(x > 0); - -#if __SIZEOF_LONG_LONG__ == 8 - return 64 - __builtin_clzll(x) - 1; -#else -#error "Wut?" -#endif -} - static inline unsigned log2u_round_up(unsigned x) { assert(x > 0); @@ -931,19 +901,19 @@ int unlink_noerrno(const char *path); (void*)memset(_new_, 0, _size_); \ }) -#define strappenda(a, ...) \ - ({ \ - int _len = strlen(a); \ - unsigned _i; \ - char *_d_, *_p_; \ - const char *_appendees_[] = { __VA_ARGS__ }; \ - for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \ - _len += strlen(_appendees_[_i]); \ - _d_ = alloca(_len + 1); \ - _p_ = stpcpy(_d_, a); \ - for (_i = 0; _i < ELEMENTSOF(_appendees_); _i++) \ - _p_ = stpcpy(_p_, _appendees_[_i]); \ - _d_; \ +#define strjoina(a, ...) \ + ({ \ + const char *_appendees_[] = { a, __VA_ARGS__ }; \ + char *_d_, *_p_; \ + int _len_ = 0; \ + unsigned _i_; \ + for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \ + _len_ += strlen(_appendees_[_i_]); \ + _p_ = _d_ = alloca(_len_ + 1); \ + for (_i_ = 0; _i_ < ELEMENTSOF(_appendees_) && _appendees_[_i_]; _i_++) \ + _p_ = stpcpy(_p_, _appendees_[_i_]); \ + *_p_ = 0; \ + _d_; \ }) #define procfs_file_alloca(pid, field) \ @@ -1020,9 +990,9 @@ int bind_remount_recursive(const char *prefix, bool ro); int fflush_and_check(FILE *f); -int tempfn_xxxxxx(const char *p, char **ret); -int tempfn_random(const char *p, char **ret); -int tempfn_random_child(const char *p, char **ret); +int tempfn_xxxxxx(const char *p, const char *extra, char **ret); +int tempfn_random(const char *p, const char *extra, char **ret); +int tempfn_random_child(const char *p, const char *extra, char **ret); bool is_localhost(const char *hostname); @@ -1031,8 +1001,15 @@ int take_password_lock(const char *root); int is_symlink(const char *path); int is_dir(const char *path, bool follow); -int unquote_first_word(const char **p, char **ret, bool relax); -int unquote_many_words(const char **p, ...) _sentinel_; +typedef enum UnquoteFlags{ + UNQUOTE_RELAX = 1, + UNQUOTE_CUNESCAPE = 2, + UNQUOTE_CUNESCAPE_RELAX = 4, +} UnquoteFlags; + +int unquote_first_word(const char **p, char **ret, UnquoteFlags flags); +int unquote_first_word_and_warn(const char **p, char **ret, UnquoteFlags flags, const char *unit, const char *filename, unsigned line, const char *rvalue); +int unquote_many_words(const char **p, UnquoteFlags flags, ...) _sentinel_; int free_and_strdup(char **p, const char *s); @@ -1063,10 +1040,9 @@ int fd_getcrtime(int fd, usec_t *usec); int path_getcrtime(const char *p, usec_t *usec); int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags); -int same_fd(int a, int b); - int chattr_fd(int fd, bool b, unsigned mask); int chattr_path(const char *p, bool b, unsigned mask); +int change_attr_fd(int fd, unsigned value, unsigned mask); int read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret); @@ -1093,3 +1069,7 @@ void sigkill_wait(pid_t *pid); #define _cleanup_sigkill_wait_ _cleanup_(sigkill_wait) int syslog_parse_priority(const char **p, int *priority, bool with_facility); + +void cmsg_close_all(struct msghdr *mh); + +int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);