X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=4cea627580fd86586acdb5bee5f966e3dde32b0a;hb=f7cf3431c7260635d9d2fa0886af05e56261c5df;hp=b4e0b778ae335c8b0a66ad983cd0adbf85a86589;hpb=f0b159f2e7b4ac8a75997834d240459f5436d36e;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index b4e0b778a..4cea62758 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -352,10 +352,7 @@ char* dirname_malloc(const char *path); void sigset_add_many(sigset_t *ss, ...); int sigprocmask_many(int how, ...); -bool hostname_is_set(void); - char* lookup_uid(uid_t uid); -char* gethostname_malloc(void); char* getlogname_malloc(void); char* getusername_malloc(void); @@ -398,9 +395,6 @@ bool nulstr_contains(const char*nulstr, const char *needle); bool plymouth_running(void); -bool hostname_is_valid(const char *s) _pure_; -char* hostname_cleanup(char *s, bool lowercase); - bool machine_name_is_valid(const char *s) _pure_; char* strshorten(char *s, size_t l); @@ -780,12 +774,27 @@ int shall_restore_state(void); * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. */ -static inline void qsort_safe(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)) { - if (nmemb) { - assert(base); - qsort(base, nmemb, size, compar); - } +static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { + if (nmemb <= 0) + return; + + assert(base); + qsort(base, nmemb, size, compar); +} + +/* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */ +static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { + + if (needlelen <= 0) + return (void*) haystack; + + if (haystacklen < needlelen) + return NULL; + + assert(haystack); + assert(needle); + + return memmem(haystack, haystacklen, needle, needlelen); } int proc_cmdline(char **ret); @@ -832,12 +841,11 @@ 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); -bool is_localhost(const char *hostname); - int take_password_lock(const char *root); int is_symlink(const char *path); int is_dir(const char *path, bool follow); +int is_device_node(const char *path); typedef enum UnquoteFlags { UNQUOTE_RELAX = 1, @@ -849,8 +857,6 @@ int unquote_many_words(const char **p, UnquoteFlags flags, ...) _sentinel_; int free_and_strdup(char **p, const char *s); -int sethostname_idempotent(const char *s); - #define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) #define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ @@ -898,3 +904,5 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char char *shell_maybe_quote(const char *s); int parse_mode(const char *s, mode_t *ret); + +int mount_move_root(const char *path);