diff options
| -rw-r--r-- | include/linux/string_helpers.h | 34 | ||||
| -rw-r--r-- | lib/string_helpers.c | 38 |
2 files changed, 38 insertions, 34 deletions
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 3eeee9672a4a..5a30f2a86239 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h | |||
| @@ -20,40 +20,6 @@ int string_get_size(u64 size, enum string_size_units units, | |||
| 20 | #define UNESCAPE_ANY \ | 20 | #define UNESCAPE_ANY \ |
| 21 | (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL) | 21 | (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL) |
| 22 | 22 | ||
| 23 | /** | ||
| 24 | * string_unescape - unquote characters in the given string | ||
| 25 | * @src: source buffer (escaped) | ||
| 26 | * @dst: destination buffer (unescaped) | ||
| 27 | * @size: size of the destination buffer (0 to unlimit) | ||
| 28 | * @flags: combination of the flags (bitwise OR): | ||
| 29 | * %UNESCAPE_SPACE: | ||
| 30 | * '\f' - form feed | ||
| 31 | * '\n' - new line | ||
| 32 | * '\r' - carriage return | ||
| 33 | * '\t' - horizontal tab | ||
| 34 | * '\v' - vertical tab | ||
| 35 | * %UNESCAPE_OCTAL: | ||
| 36 | * '\NNN' - byte with octal value NNN (1 to 3 digits) | ||
| 37 | * %UNESCAPE_HEX: | ||
| 38 | * '\xHH' - byte with hexadecimal value HH (1 to 2 digits) | ||
| 39 | * %UNESCAPE_SPECIAL: | ||
| 40 | * '\"' - double quote | ||
| 41 | * '\\' - backslash | ||
| 42 | * '\a' - alert (BEL) | ||
| 43 | * '\e' - escape | ||
| 44 | * %UNESCAPE_ANY: | ||
| 45 | * all previous together | ||
| 46 | * | ||
| 47 | * Returns amount of characters processed to the destination buffer excluding | ||
| 48 | * trailing '\0'. | ||
| 49 | * | ||
| 50 | * Because the size of the output will be the same as or less than the size of | ||
| 51 | * the input, the transformation may be performed in place. | ||
| 52 | * | ||
| 53 | * Caller must provide valid source and destination pointers. Be aware that | ||
| 54 | * destination buffer will always be NULL-terminated. Source string must be | ||
| 55 | * NULL-terminated as well. | ||
| 56 | */ | ||
| 57 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags); | 23 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags); |
| 58 | 24 | ||
| 59 | static inline int string_unescape_inplace(char *buf, unsigned int flags) | 25 | static inline int string_unescape_inplace(char *buf, unsigned int flags) |
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 29033f319aea..74ec60469640 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
| @@ -168,6 +168,44 @@ static bool unescape_special(char **src, char **dst) | |||
| 168 | return true; | 168 | return true; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | /** | ||
| 172 | * string_unescape - unquote characters in the given string | ||
| 173 | * @src: source buffer (escaped) | ||
| 174 | * @dst: destination buffer (unescaped) | ||
| 175 | * @size: size of the destination buffer (0 to unlimit) | ||
| 176 | * @flags: combination of the flags (bitwise OR): | ||
| 177 | * %UNESCAPE_SPACE: | ||
| 178 | * '\f' - form feed | ||
| 179 | * '\n' - new line | ||
| 180 | * '\r' - carriage return | ||
| 181 | * '\t' - horizontal tab | ||
| 182 | * '\v' - vertical tab | ||
| 183 | * %UNESCAPE_OCTAL: | ||
| 184 | * '\NNN' - byte with octal value NNN (1 to 3 digits) | ||
| 185 | * %UNESCAPE_HEX: | ||
| 186 | * '\xHH' - byte with hexadecimal value HH (1 to 2 digits) | ||
| 187 | * %UNESCAPE_SPECIAL: | ||
| 188 | * '\"' - double quote | ||
| 189 | * '\\' - backslash | ||
| 190 | * '\a' - alert (BEL) | ||
| 191 | * '\e' - escape | ||
| 192 | * %UNESCAPE_ANY: | ||
| 193 | * all previous together | ||
| 194 | * | ||
| 195 | * Description: | ||
| 196 | * The function unquotes characters in the given string. | ||
| 197 | * | ||
| 198 | * Because the size of the output will be the same as or less than the size of | ||
| 199 | * the input, the transformation may be performed in place. | ||
| 200 | * | ||
| 201 | * Caller must provide valid source and destination pointers. Be aware that | ||
| 202 | * destination buffer will always be NULL-terminated. Source string must be | ||
| 203 | * NULL-terminated as well. | ||
| 204 | * | ||
| 205 | * Return: | ||
| 206 | * The amount of the characters processed to the destination buffer excluding | ||
| 207 | * trailing '\0' is returned. | ||
| 208 | */ | ||
| 171 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags) | 209 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags) |
| 172 | { | 210 | { |
| 173 | char *out = dst; | 211 | char *out = dst; |
