From 7b19627697b48a0660b1667fcd4597f32eb14b6a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Sun, 20 Feb 2022 12:17:10 +0100 Subject: [PATCH] fundamental: Move some helpers into string-util-fundamental --- src/basic/string-util.h | 11 ----------- src/basic/strv.h | 6 ------ src/fundamental/string-util-fundamental.h | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 60e80484a3..1dd46f7f20 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -29,10 +29,6 @@ static inline char* strstr_ptr(const char *haystack, const char *needle) { return strstr(haystack, needle); } -static inline const char* strempty(const char *s) { - return s ?: ""; -} - static inline const char* strnull(const char *s) { return s ?: "(null)"; } @@ -181,13 +177,6 @@ int free_and_strndup(char **p, const char *s, size_t l); bool string_is_safe(const char *p) _pure_; -static inline size_t strlen_ptr(const char *s) { - if (!s) - return 0; - - return strlen(s); -} - DISABLE_WARNING_STRINGOP_TRUNCATION; static inline void strncpy_exact(char *buf, const char *src, size_t buf_len) { strncpy(buf, src, buf_len); diff --git a/src/basic/strv.h b/src/basic/strv.h index c567785cdb..072739df35 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -140,12 +140,6 @@ static inline int strv_from_nulstr(char ***a, const char *nulstr) { bool strv_overlap(char * const *a, char * const *b) _pure_; -#define _STRV_FOREACH(s, l, i) \ - for (typeof(*(l)) *s, *i = (l); (s = i) && *i; i++) - -#define STRV_FOREACH(s, l) \ - _STRV_FOREACH(s, l, UNIQ_T(i, UNIQ)) - #define _STRV_FOREACH_BACKWARDS(s, l, h, i) \ for (typeof(*(l)) *s, *h = (l), *i = ({ \ size_t _len = strv_length(h); \ diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h index dc0c1202be..101c2ae1b6 100644 --- a/src/fundamental/string-util-fundamental.h +++ b/src/fundamental/string-util-fundamental.h @@ -50,6 +50,13 @@ static inline sd_bool strcaseeq_ptr(const sd_char *a, const sd_char *b) { return strcasecmp_ptr(a, b) == 0; } +static inline size_t strlen_ptr(const sd_char *s) { + if (!s) + return 0; + + return strlen(s); +} + sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_; #ifndef SD_BOOT sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_; @@ -61,6 +68,10 @@ static inline sd_bool isempty(const sd_char *a) { return !a || a[0] == '\0'; } +static inline const sd_char *strempty(const sd_char *s) { + return s ?: STR_C(""); +} + static inline const sd_char *yes_no(sd_bool b) { return b ? STR_C("yes") : STR_C("no"); } @@ -82,3 +93,9 @@ static inline void *memory_startswith(const void *p, size_t sz, const sd_char *t return (uint8_t*) p + n; } + +#define _STRV_FOREACH(s, l, i) \ + for (typeof(*(l)) *s, *i = (l); (s = i) && *i; i++) + +#define STRV_FOREACH(s, l) \ + _STRV_FOREACH(s, l, UNIQ_T(i, UNIQ)) -- 2.25.1