1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

fundamental: Move some helpers into string-util-fundamental

This commit is contained in:
Jan Janssen 2022-02-20 12:17:10 +01:00 committed by Luca Boccassi
parent f386daa054
commit 7b19627697
3 changed files with 17 additions and 17 deletions

View 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);

View 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); \

View 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))