chiark / gitweb /
dbus: import struct unit_info from systemctl
[elogind.git] / src / shared / util.h
index 25b349a17a0c1ff9be109963635b7a69ee521186..fcb0d9af177e3fa78a1040572a2eeac262c25f0b 100644 (file)
@@ -60,13 +60,13 @@ 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())
 
 #define streq(a,b) (strcmp((a),(b)) == 0)
 #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
+#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
+#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
 
 bool streq_ptr(const char *a, const char *b);
 
@@ -433,6 +433,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);
@@ -522,6 +524,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);
@@ -541,7 +544,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 *),
@@ -553,6 +558,7 @@ typedef enum DrawSpecialChar {
         DRAW_TREE_VERT,
         DRAW_TREE_BRANCH,
         DRAW_TREE_RIGHT,
+        DRAW_TREE_SPACE,
         DRAW_TRIANGULAR_BULLET,
         _DRAW_SPECIAL_CHAR_MAX
 } DrawSpecialChar;
@@ -561,3 +567,28 @@ 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(line, f, on_error)                         \
+        for (;;)                                                \
+                if (!fgets(line, sizeof(line), f)) {            \
+                        if (ferror(f)) {                        \
+                                on_error;                       \
+                        }                                       \
+                        break;                                  \
+                } else
+
+#define FOREACH_DIRENT(de, d, on_error)                                 \
+        for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d))   \
+                if (!de) {                                              \
+                        if (errno != 0) {                               \
+                                on_error;                               \
+                        }                                               \
+                        break;                                          \
+                } else if (ignore_file((de)->d_name))                   \
+                        continue;                                       \
+                else