X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=cd13457528c14d2727483b1497e673adc404c9db;hb=fabe5c0e5fce730aa66e10a9c4f9fdd443d7aeda;hp=af18d0b657f4ebe70c347ba17efaf0255c675175;hpb=9a98c7a156709ae16f7e043f866ecb452ce906f8;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index af18d0b65..cd1345752 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -46,7 +46,6 @@ union dirent_storage { ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))]; }; - /* What is interpreted as whitespace? */ #define WHITESPACE " \t\n\r" #define NEWLINE "\n\r" @@ -61,8 +60,6 @@ union dirent_storage { #define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m" #define ANSI_HIGHLIGHT_OFF "\x1B[0m" -bool is_efiboot(void); - size_t page_size(void); #define PAGE_ALIGN(l) ALIGN_TO((l), page_size()) @@ -434,6 +431,8 @@ int get_group_creds(const char **groupname, gid_t *gid); int in_group(const char *name); +char* uid_to_name(uid_t uid); + int glob_exists(const char *path); int dirent_ensure_type(DIR *d, struct dirent *de); @@ -523,6 +522,7 @@ int get_home_dir(char **ret); void freep(void *p); void fclosep(FILE **f); +void pclosep(FILE **f); void closep(int *fd); void closedirp(DIR **d); void umaskp(mode_t *u); @@ -542,7 +542,9 @@ _malloc_ static inline void *memdup_multiply(const void *p, size_t a, size_t b) } bool filename_is_safe(const char *p); +bool path_is_safe(const char *p); bool string_is_safe(const char *p); +bool string_has_cc(const char *p); void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), @@ -554,9 +556,26 @@ typedef enum DrawSpecialChar { DRAW_TREE_VERT, DRAW_TREE_BRANCH, DRAW_TREE_RIGHT, + DRAW_TREE_SPACE, DRAW_TRIANGULAR_BULLET, _DRAW_SPECIAL_CHAR_MAX } DrawSpecialChar; const char *draw_special_char(DrawSpecialChar ch); char *strreplace(const char *text, const char *old_string, const char *new_string); + +char *strip_tab_ansi(char **p, size_t *l); + +int on_ac_power(void); + +int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f); +int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f); + +#define FOREACH_LINE(f, line, on_error) \ + for (char line[LINE_MAX]; !feof(f); ) \ + if (!fgets(line, sizeof(line), f)) { \ + if (ferror(f)) { \ + on_error; \ + } \ + break; \ + } else