X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fbasic%2Fstring-util.h;h=e8c2fc6dd38f55c9b0085d1bdeecfcfd39cf440c;hb=d93247127eb2e073a6d3b5bcc67bcc4048d674fe;hp=7ed649ae6cd4a88c2ac5d8295f675a4a3b441481;hpb=3b22b89bce6c5185e1db0a28390a0e6df138a27b;p=elogind.git
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 7ed649ae6..e8c2fc6dd 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
#pragma once
/***
@@ -21,7 +19,9 @@
along with systemd; If not, see .
***/
+#include
#include
+#include
#include
#include "macro.h"
@@ -37,6 +37,7 @@
#define UPPERCASE_LETTERS "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LETTERS LOWERCASE_LETTERS UPPERCASE_LETTERS
#define ALPHANUMERICAL LETTERS DIGITS
+#define HEXDIGITS DIGITS "abcdefABCDEF"
#define streq(a,b) (strcmp((a),(b)) == 0)
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
@@ -65,6 +66,16 @@ static inline bool isempty(const char *p) {
return !p || !p[0];
}
+static inline const char *empty_to_null(const char *p) {
+ return isempty(p) ? NULL : p;
+}
+
+#if 0 /// UNNEEDED by elogind
+static inline const char *strdash_if_empty(const char *str) {
+ return isempty(str) ? "-" : str;
+}
+#endif // 0
+
static inline char *startswith(const char *s, const char *prefix) {
size_t l;
@@ -75,6 +86,7 @@ static inline char *startswith(const char *s, const char *prefix) {
return NULL;
}
+#if 0 /// UNNEEDED by elogind
static inline char *startswith_no_case(const char *s, const char *prefix) {
size_t l;
@@ -84,6 +96,7 @@ static inline char *startswith_no_case(const char *s, const char *prefix) {
return NULL;
}
+#endif // 0
char *endswith(const char *s, const char *postfix) _pure_;
char *endswith_no_case(const char *s, const char *postfix) _pure_;
@@ -98,16 +111,14 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
_FOREACH_WORD(word, length, s, separator, false, state)
-#define FOREACH_WORD_QUOTED(word, length, s, state) \
- _FOREACH_WORD(word, length, s, WHITESPACE, true, state)
-
#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
char *strappend(const char *s, const char *suffix);
char *strnappend(const char *s, const char *suffix, size_t length);
-char *strjoin(const char *x, ...) _sentinel_;
+char *strjoin_real(const char *x, ...) _sentinel_;
+#define strjoin(a, ...) strjoin_real((a), __VA_ARGS__, NULL)
#define strjoina(a, ...) \
({ \
@@ -125,17 +136,24 @@ char *strjoin(const char *x, ...) _sentinel_;
})
char *strstrip(char *s);
+#if 0 /// UNNEEDED by elogind
char *delete_chars(char *s, const char *bad);
+#endif // 0
char *truncate_nl(char *s);
+#if 0 /// UNNEEDED by elogind
char ascii_tolower(char x);
char *ascii_strlower(char *s);
char *ascii_strlower_n(char *s, size_t n);
+char ascii_toupper(char x);
+char *ascii_strupper(char *s);
+
int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);
bool chars_intersect(const char *a, const char *b) _pure_;
+#endif // 0
static inline bool _pure_ in_charset(const char *s, const char* charset) {
assert(s);
@@ -179,7 +197,10 @@ static inline void *memmem_safe(const void *haystack, size_t haystacklen, const
return memmem(haystack, haystacklen, needle, needlelen);
}
-void* memory_erase(void *p, size_t l);
+#if !HAVE_DECL_EXPLICIT_BZERO
+void explicit_bzero(void *p, size_t l);
+#endif
+
char *string_erase(char *x);
char *string_free_erase(char *s);