]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: move string_is_safe() to string-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 20:26:33 +0000 (21:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:56 +0000 (13:25 +0100)
src/basic/string-util.c
src/basic/string-util.h
src/basic/util.c
src/basic/util.h

index a7cf4e85205d0f9854dd7827752a2ea12de7cc2c..a1781c505aa63c0c88f74d18bb4045a4687f3782 100644 (file)
@@ -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;
+}
index 7b7c0e5f325b305694fa1ba43eebe67f90f1e584..297b8f8232dcde12826b014132b8623d37737aa7 100644 (file)
@@ -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_;
index 92ce009620f681cfdfa32137bd558798466c10fd..b85e3c020a8f65ee277df9158679ed93ffab3cd8 100644 (file)
@@ -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) {
index 7608e49689e317f5bacdff4222b6d731acd878b6..c268c6d0c389fdb8a8e8b24880cdedd6d0a3ef9d 100644 (file)
@@ -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.
  */