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