1 #ifndef _LINUX_STRING_HELPERS_H_
2 #define _LINUX_STRING_HELPERS_H_
4 #include <linux/types.h>
6 /* Descriptions of the types of units to
8 enum string_size_units {
9 STRING_UNITS_10, /* use powers of 10^3 (standard SI) */
10 STRING_UNITS_2, /* use binary powers of 2^10 */
13 int string_get_size(u64 size, enum string_size_units units,
16 #define UNESCAPE_SPACE 0x01
17 #define UNESCAPE_OCTAL 0x02
18 #define UNESCAPE_HEX 0x04
19 #define UNESCAPE_SPECIAL 0x08
20 #define UNESCAPE_ANY \
21 (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL)
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):
32 * '\r' - carriage return
33 * '\t' - horizontal tab
36 * '\NNN' - byte with octal value NNN (1 to 3 digits)
38 * '\xHH' - byte with hexadecimal value HH (1 to 2 digits)
45 * all previous together
47 * Returns amount of characters processed to the destination buffer excluding
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.
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.
57 int string_unescape(char *src, char *dst, size_t size, unsigned int flags);
59 static inline int string_unescape_inplace(char *buf, unsigned int flags)
61 return string_unescape(buf, buf, 0, flags);
64 static inline int string_unescape_any(char *src, char *dst, size_t size)
66 return string_unescape(src, dst, size, UNESCAPE_ANY);
69 static inline int string_unescape_any_inplace(char *buf)
71 return string_unescape_any(buf, buf, 0);