util: move string_is_safe() to string-util.[ch]
This commit is contained in:
parent
f4f15635ec
commit
f3e2e81d53
|
@ -765,3 +765,20 @@ char *string_free_erase(char *s) {
|
||||||
string_erase(s);
|
string_erase(s);
|
||||||
return mfree(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;
|
||||||
|
}
|
||||||
|
|
|
@ -168,3 +168,5 @@ void string_erase(char *x);
|
||||||
char *string_free_erase(char *s);
|
char *string_free_erase(char *s);
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
|
||||||
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
|
||||||
|
|
||||||
|
bool string_is_safe(const char *p) _pure_;
|
||||||
|
|
|
@ -886,23 +886,6 @@ bool in_initrd(void) {
|
||||||
return saved;
|
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 */
|
/* 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,
|
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
||||||
int (*compar) (const void *, const void *, void *), void *arg) {
|
int (*compar) (const void *, const void *, void *), void *arg) {
|
||||||
|
|
|
@ -262,8 +262,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
|
||||||
return memdup(p, a * b);
|
return memdup(p, a * b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool string_is_safe(const char *p) _pure_;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a string contains any glob patterns.
|
* Check if a string contains any glob patterns.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue