diff options
author | Mark Hindley <mark@hindley.org.uk> | 2018-11-12 09:10:28 +0000 |
---|---|---|
committer | Mark Hindley <mark@hindley.org.uk> | 2018-11-12 09:21:21 +0000 |
commit | 2cc17d30309a1db16cccbf376a59ae40e47b6959 (patch) | |
tree | cd51ee95799631af348ebae8630a69219bee99cd /src/basic/string-util.h | |
parent | ae65e91a5439f395e0da0cd8ffda95d6289849e1 (diff) | |
parent | d4a3f291e3955648ea1d29e674b0f8f9b1556257 (diff) |
Merge remote-tracking branch 'upstream/v239-stable' into merge_upstream.
Diffstat (limited to 'src/basic/string-util.h')
-rw-r--r-- | src/basic/string-util.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/basic/string-util.h b/src/basic/string-util.h index d3a01a65e..f0f73dd47 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -52,11 +52,9 @@ static inline const char *empty_to_null(const char *p) { return isempty(p) ? NULL : p; } -#if 0 /// UNNEEDED by elogind static inline const char *empty_to_dash(const char *str) { return isempty(str) ? "-" : str; } -#endif // 0 static inline char *startswith(const char *s, const char *prefix) { size_t l; @@ -182,6 +180,7 @@ char *strrep(const char *s, unsigned n); int split_pair(const char *s, const char *sep, char **l, char **r); int free_and_strdup(char **p, const char *s); +int free_and_strndup(char **p, const char *s, size_t l); /* Normal memmem() requires haystack to be nonnull, which is annoying for zero-length buffers */ static inline void *memmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { @@ -234,3 +233,27 @@ static inline void *memory_startswith(const void *p, size_t sz, const char *toke return (uint8_t*) p + n; } + +#if 0 /// Not needed by elogind, only test-string-util uses this. +/* Like startswith_no_case(), but operates on arbitrary memory blocks. + * It works only for ASCII strings. + */ +static inline void *memory_startswith_no_case(const void *p, size_t sz, const char *token) { + size_t n, i; + + assert(token); + + n = strlen(token); + if (sz < n) + return NULL; + + assert(p); + + for (i = 0; i < n; i++) { + if (ascii_tolower(((char *)p)[i]) != ascii_tolower(token[i])) + return NULL; + } + + return (uint8_t*) p + n; +} +#endif // 0 |