X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=19cc36af843dd622bdb2a5aad80d57e07cf8342b;hp=d926b01919ec0436c6fe1ca72016e0f7dfa6999e;hb=f7900e258dfb8ab55f333d02d96f908ca0ea8899;hpb=f74e605fc06c1c23e968dc4c26045eb746791706 diff --git a/src/shared/util.h b/src/shared/util.h index d926b0191..19cc36af8 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -65,6 +65,8 @@ size_t page_size(void); #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); @@ -120,6 +122,8 @@ int safe_atoi(const char *s, int *ret_i); int safe_atollu(const char *s, unsigned long long *ret_u); int safe_atolli(const char *s, long long int *ret_i); +int safe_atod(const char *s, double *ret_d); + #if __WORDSIZE == 32 static inline int safe_atolu(const char *s, unsigned long *ret_u) { assert_cc(sizeof(unsigned long) == sizeof(unsigned)); @@ -175,15 +179,6 @@ char *split_quoted(const char *c, size_t *l, char **state); pid_t get_parent_of_pid(pid_t pid, pid_t *ppid); int get_starttime_of_pid(pid_t pid, unsigned long long *st); -int write_one_line_file(const char *fn, const char *line); -int write_one_line_file_atomic(const char *fn, const char *line); -int read_one_line_file(const char *fn, char **line); -int read_full_file(const char *fn, char **contents, size_t *size); - -int parse_env_file(const char *fname, const char *separator, ...) _sentinel_; -int load_env_file(const char *fname, char ***l); -int write_env_file(const char *fname, char **l); - char *strappend(const char *s, const char *suffix); char *strnappend(const char *s, const char *suffix, size_t length); @@ -568,11 +563,25 @@ char *strip_tab_ansi(char **p, size_t *l); int on_ac_power(void); -#define FOREACH_LINE(f, line, on_error) \ - for (char line[LINE_MAX]; !feof(f); ) \ +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