summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/string-util.c17
-rw-r--r--src/basic/string-util.h2
-rw-r--r--src/basic/util.c17
-rw-r--r--src/basic/util.h2
4 files changed, 19 insertions, 19 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index a7cf4e8520..a1781c505a 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -765,3 +765,20 @@ char *string_free_erase(char *s) {
string_erase(s);
return mfree(s);
}
+
+bool string_is_safe(const char *p) {
+ const char *t;
+
+ if (!p)
+ return false;
+
+ for (t = p; *t; t++) {
+ if (*t > 0 && *t < ' ') /* no control characters */
+ return false;
+
+ if (strchr(QUOTES "\\\x7f", *t))
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 7b7c0e5f32..297b8f8232 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -168,3 +168,5 @@ void string_erase(char *x);
char *string_free_erase(char *s);
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
+
+bool string_is_safe(const char *p) _pure_;
diff --git a/src/basic/util.c b/src/basic/util.c
index 92ce009620..b85e3c020a 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -886,23 +886,6 @@ bool in_initrd(void) {
return saved;
}
-bool string_is_safe(const char *p) {
- const char *t;
-
- if (!p)
- return false;
-
- for (t = p; *t; t++) {
- if (*t > 0 && *t < ' ')
- return false;
-
- if (strchr("\\\"\'\x7f", *t))
- return false;
- }
-
- return true;
-}
-
/* hey glibc, APIs with callbacks without a user pointer are so useless */
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar) (const void *, const void *, void *), void *arg) {
diff --git a/src/basic/util.h b/src/basic/util.h
index 7608e49689..c268c6d0c3 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -262,8 +262,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
return memdup(p, a * b);
}
-bool string_is_safe(const char *p) _pure_;
-
/**
* Check if a string contains any glob patterns.
*/