mirror of
https://github.com/systemd/systemd.git
synced 2025-01-25 10:04:04 +03:00
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);
|
||||
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);
|
||||
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_;
|
||||
|
@ -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) {
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user