]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/string_helpers.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_STRING_HELPERS_H_
3 #define _LINUX_STRING_HELPERS_H_
5 #include <linux/types.h>
10 /* Descriptions of the types of units to
12 enum string_size_units
{
13 STRING_UNITS_10
, /* use powers of 10^3 (standard SI) */
14 STRING_UNITS_2
, /* use binary powers of 2^10 */
17 void string_get_size(u64 size
, u64 blk_size
, enum string_size_units units
,
20 #define UNESCAPE_SPACE 0x01
21 #define UNESCAPE_OCTAL 0x02
22 #define UNESCAPE_HEX 0x04
23 #define UNESCAPE_SPECIAL 0x08
24 #define UNESCAPE_ANY \
25 (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL)
27 int string_unescape(char *src
, char *dst
, size_t size
, unsigned int flags
);
29 static inline int string_unescape_inplace(char *buf
, unsigned int flags
)
31 return string_unescape(buf
, buf
, 0, flags
);
34 static inline int string_unescape_any(char *src
, char *dst
, size_t size
)
36 return string_unescape(src
, dst
, size
, UNESCAPE_ANY
);
39 static inline int string_unescape_any_inplace(char *buf
)
41 return string_unescape_any(buf
, buf
, 0);
44 #define ESCAPE_SPACE 0x01
45 #define ESCAPE_SPECIAL 0x02
46 #define ESCAPE_NULL 0x04
47 #define ESCAPE_OCTAL 0x08
49 (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL)
50 #define ESCAPE_NP 0x10
51 #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP)
52 #define ESCAPE_HEX 0x20
54 int string_escape_mem(const char *src
, size_t isz
, char *dst
, size_t osz
,
55 unsigned int flags
, const char *only
);
57 int string_escape_mem_ascii(const char *src
, size_t isz
, char *dst
,
60 static inline int string_escape_mem_any_np(const char *src
, size_t isz
,
61 char *dst
, size_t osz
, const char *only
)
63 return string_escape_mem(src
, isz
, dst
, osz
, ESCAPE_ANY_NP
, only
);
66 static inline int string_escape_str(const char *src
, char *dst
, size_t sz
,
67 unsigned int flags
, const char *only
)
69 return string_escape_mem(src
, strlen(src
), dst
, sz
, flags
, only
);
72 static inline int string_escape_str_any_np(const char *src
, char *dst
,
73 size_t sz
, const char *only
)
75 return string_escape_str(src
, dst
, sz
, ESCAPE_ANY_NP
, only
);
78 char *kstrdup_quotable(const char *src
, gfp_t gfp
);
79 char *kstrdup_quotable_cmdline(struct task_struct
*task
, gfp_t gfp
);
80 char *kstrdup_quotable_file(struct file
*file
, gfp_t gfp
);