]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental: Move some helpers into string-util-fundamental
authorJan Janssen <medhefgo@web.de>
Sun, 20 Feb 2022 11:17:10 +0000 (12:17 +0100)
committerLuca Boccassi <bluca@debian.org>
Sat, 21 May 2022 14:11:13 +0000 (15:11 +0100)
src/basic/string-util.h
src/basic/strv.h
src/fundamental/string-util-fundamental.h

index 60e80484a346b92cb5dce760c5a82a2f24c0d0f5..1dd46f7f2032c80548cbcf2289b519735a0543a2 100644 (file)
@@ -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);
index c567785cdb7530448eda8318e4396b634c739cfd..072739df355518abff28da8bb391ea1ea409e845 100644 (file)
@@ -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);           \
index dc0c1202be9115f544f2c3f7660e37d78230050e..101c2ae1b6652b34db537ca29a9a75d91cc5bfff 100644 (file)
@@ -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))