Commit | Line | Data |
---|---|---|
3c9f3681 JB |
1 | #ifndef _LINUX_STRING_HELPERS_H_ |
2 | #define _LINUX_STRING_HELPERS_H_ | |
3 | ||
4 | #include <linux/types.h> | |
5 | ||
21985319 KC |
6 | struct file; |
7 | ||
3c9f3681 JB |
8 | /* Descriptions of the types of units to |
9 | * print in */ | |
10 | enum string_size_units { | |
11 | STRING_UNITS_10, /* use powers of 10^3 (standard SI) */ | |
12 | STRING_UNITS_2, /* use binary powers of 2^10 */ | |
13 | }; | |
14 | ||
b9f28d86 | 15 | void string_get_size(u64 size, u64 blk_size, enum string_size_units units, |
d1214c65 | 16 | char *buf, int len); |
3c9f3681 | 17 | |
16c7fa05 AS |
18 | #define UNESCAPE_SPACE 0x01 |
19 | #define UNESCAPE_OCTAL 0x02 | |
20 | #define UNESCAPE_HEX 0x04 | |
21 | #define UNESCAPE_SPECIAL 0x08 | |
22 | #define UNESCAPE_ANY \ | |
23 | (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL) | |
24 | ||
16c7fa05 AS |
25 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags); |
26 | ||
27 | static inline int string_unescape_inplace(char *buf, unsigned int flags) | |
28 | { | |
29 | return string_unescape(buf, buf, 0, flags); | |
30 | } | |
31 | ||
32 | static inline int string_unescape_any(char *src, char *dst, size_t size) | |
33 | { | |
34 | return string_unescape(src, dst, size, UNESCAPE_ANY); | |
35 | } | |
36 | ||
37 | static inline int string_unescape_any_inplace(char *buf) | |
38 | { | |
39 | return string_unescape_any(buf, buf, 0); | |
40 | } | |
41 | ||
c8250381 AS |
42 | #define ESCAPE_SPACE 0x01 |
43 | #define ESCAPE_SPECIAL 0x02 | |
44 | #define ESCAPE_NULL 0x04 | |
45 | #define ESCAPE_OCTAL 0x08 | |
46 | #define ESCAPE_ANY \ | |
47 | (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL) | |
48 | #define ESCAPE_NP 0x10 | |
49 | #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP) | |
50 | #define ESCAPE_HEX 0x20 | |
51 | ||
41416f23 | 52 | int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, |
b40bdb7f | 53 | unsigned int flags, const char *only); |
c8250381 AS |
54 | |
55 | static inline int string_escape_mem_any_np(const char *src, size_t isz, | |
b40bdb7f | 56 | char *dst, size_t osz, const char *only) |
c8250381 | 57 | { |
b40bdb7f | 58 | return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, only); |
c8250381 AS |
59 | } |
60 | ||
41416f23 | 61 | static inline int string_escape_str(const char *src, char *dst, size_t sz, |
b40bdb7f | 62 | unsigned int flags, const char *only) |
c8250381 | 63 | { |
b40bdb7f | 64 | return string_escape_mem(src, strlen(src), dst, sz, flags, only); |
c8250381 AS |
65 | } |
66 | ||
41416f23 | 67 | static inline int string_escape_str_any_np(const char *src, char *dst, |
b40bdb7f | 68 | size_t sz, const char *only) |
c8250381 | 69 | { |
b40bdb7f | 70 | return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, only); |
c8250381 AS |
71 | } |
72 | ||
b53f27e4 | 73 | char *kstrdup_quotable(const char *src, gfp_t gfp); |
0d044328 | 74 | char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); |
21985319 | 75 | char *kstrdup_quotable_file(struct file *file, gfp_t gfp); |
b53f27e4 | 76 | |
3c9f3681 | 77 | #endif |