util: move string_is_safe() to string-util.[ch]

This commit is contained in:
Lennart Poettering 2015-10-26 21:26:33 +01:00
parent f4f15635ec
commit f3e2e81d53
4 changed files with 19 additions and 19 deletions

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

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

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

View 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.
*/