]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/string_helpers.h
iommu/amd: Remove PD_DMA_OPS_MASK
[mirror_ubuntu-jammy-kernel.git] / include / linux / string_helpers.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
3c9f3681
JB
2#ifndef _LINUX_STRING_HELPERS_H_
3#define _LINUX_STRING_HELPERS_H_
4
5#include <linux/types.h>
6
21985319 7struct file;
c6d24c32 8struct task_struct;
21985319 9
3c9f3681
JB
10/* Descriptions of the types of units to
11 * print in */
12enum string_size_units {
13 STRING_UNITS_10, /* use powers of 10^3 (standard SI) */
14 STRING_UNITS_2, /* use binary powers of 2^10 */
15};
16
b9f28d86 17void string_get_size(u64 size, u64 blk_size, enum string_size_units units,
d1214c65 18 char *buf, int len);
3c9f3681 19
16c7fa05
AS
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)
26
16c7fa05
AS
27int string_unescape(char *src, char *dst, size_t size, unsigned int flags);
28
29static inline int string_unescape_inplace(char *buf, unsigned int flags)
30{
31 return string_unescape(buf, buf, 0, flags);
32}
33
34static inline int string_unescape_any(char *src, char *dst, size_t size)
35{
36 return string_unescape(src, dst, size, UNESCAPE_ANY);
37}
38
39static inline int string_unescape_any_inplace(char *buf)
40{
41 return string_unescape_any(buf, buf, 0);
42}
43
c8250381
AS
44#define ESCAPE_SPACE 0x01
45#define ESCAPE_SPECIAL 0x02
46#define ESCAPE_NULL 0x04
47#define ESCAPE_OCTAL 0x08
48#define ESCAPE_ANY \
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
53
41416f23 54int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
b40bdb7f 55 unsigned int flags, const char *only);
c8250381 56
ea053e16
BF
57int string_escape_mem_ascii(const char *src, size_t isz, char *dst,
58 size_t osz);
59
c8250381 60static inline int string_escape_mem_any_np(const char *src, size_t isz,
b40bdb7f 61 char *dst, size_t osz, const char *only)
c8250381 62{
b40bdb7f 63 return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, only);
c8250381
AS
64}
65
41416f23 66static inline int string_escape_str(const char *src, char *dst, size_t sz,
b40bdb7f 67 unsigned int flags, const char *only)
c8250381 68{
b40bdb7f 69 return string_escape_mem(src, strlen(src), dst, sz, flags, only);
c8250381
AS
70}
71
41416f23 72static inline int string_escape_str_any_np(const char *src, char *dst,
b40bdb7f 73 size_t sz, const char *only)
c8250381 74{
b40bdb7f 75 return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, only);
c8250381
AS
76}
77
b53f27e4 78char *kstrdup_quotable(const char *src, gfp_t gfp);
0d044328 79char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
21985319 80char *kstrdup_quotable_file(struct file *file, gfp_t gfp);
b53f27e4 81
3c9f3681 82#endif