diff options
Diffstat (limited to 'include/linux/string_helpers.h')
| -rw-r--r-- | include/linux/string_helpers.h | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 3eeee9672a4a..6eb567ac56bc 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) |
| @@ -71,4 +37,35 @@ static inline int string_unescape_any_inplace(char *buf) | |||
| 71 | return string_unescape_any(buf, buf, 0); | 37 | return string_unescape_any(buf, buf, 0); |
| 72 | } | 38 | } |
| 73 | 39 | ||
| 40 | #define ESCAPE_SPACE 0x01 | ||
| 41 | #define ESCAPE_SPECIAL 0x02 | ||
| 42 | #define ESCAPE_NULL 0x04 | ||
| 43 | #define ESCAPE_OCTAL 0x08 | ||
| 44 | #define ESCAPE_ANY \ | ||
| 45 | (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL) | ||
| 46 | #define ESCAPE_NP 0x10 | ||
| 47 | #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP) | ||
| 48 | #define ESCAPE_HEX 0x20 | ||
| 49 | |||
| 50 | int string_escape_mem(const char *src, size_t isz, char **dst, size_t osz, | ||
| 51 | unsigned int flags, const char *esc); | ||
| 52 | |||
| 53 | static inline int string_escape_mem_any_np(const char *src, size_t isz, | ||
| 54 | char **dst, size_t osz, const char *esc) | ||
| 55 | { | ||
| 56 | return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, esc); | ||
| 57 | } | ||
| 58 | |||
| 59 | static inline int string_escape_str(const char *src, char **dst, size_t sz, | ||
| 60 | unsigned int flags, const char *esc) | ||
| 61 | { | ||
| 62 | return string_escape_mem(src, strlen(src), dst, sz, flags, esc); | ||
| 63 | } | ||
| 64 | |||
| 65 | static inline int string_escape_str_any_np(const char *src, char **dst, | ||
| 66 | size_t sz, const char *esc) | ||
| 67 | { | ||
| 68 | return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, esc); | ||
| 69 | } | ||
| 70 | |||
| 74 | #endif | 71 | #endif |
