~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/string_helpers.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_STRING_HELPERS_H_
  3 #define _LINUX_STRING_HELPERS_H_
  4 
  5 #include <linux/bits.h>
  6 #include <linux/ctype.h>
  7 #include <linux/string_choices.h>
  8 #include <linux/string.h>
  9 #include <linux/types.h>
 10 
 11 struct device;
 12 struct file;
 13 struct task_struct;
 14 
 15 static inline bool string_is_terminated(const char *s, int len)
 16 {
 17         return memchr(s, '\0', len) ? true : false;
 18 }
 19 
 20 /* Descriptions of the types of units to print in */
 21 enum string_size_units {
 22         STRING_UNITS_10,        /* use powers of 10^3 (standard SI) */
 23         STRING_UNITS_2,         /* use binary powers of 2^10 */
 24         STRING_UNITS_MASK       = BIT(0),
 25 
 26         /* Modifiers */
 27         STRING_UNITS_NO_SPACE   = BIT(30),
 28         STRING_UNITS_NO_BYTES   = BIT(31),
 29 };
 30 
 31 int string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
 32                     char *buf, int len);
 33 
 34 int parse_int_array_user(const char __user *from, size_t count, int **array);
 35 
 36 #define UNESCAPE_SPACE          BIT(0)
 37 #define UNESCAPE_OCTAL          BIT(1)
 38 #define UNESCAPE_HEX            BIT(2)
 39 #define UNESCAPE_SPECIAL        BIT(3)
 40 #define UNESCAPE_ANY            \
 41         (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL)
 42 
 43 #define UNESCAPE_ALL_MASK       GENMASK(3, 0)
 44 
 45 int string_unescape(char *src, char *dst, size_t size, unsigned int flags);
 46 
 47 static inline int string_unescape_inplace(char *buf, unsigned int flags)
 48 {
 49         return string_unescape(buf, buf, 0, flags);
 50 }
 51 
 52 static inline int string_unescape_any(char *src, char *dst, size_t size)
 53 {
 54         return string_unescape(src, dst, size, UNESCAPE_ANY);
 55 }
 56 
 57 static inline int string_unescape_any_inplace(char *buf)
 58 {
 59         return string_unescape_any(buf, buf, 0);
 60 }
 61 
 62 #define ESCAPE_SPACE            BIT(0)
 63 #define ESCAPE_SPECIAL          BIT(1)
 64 #define ESCAPE_NULL             BIT(2)
 65 #define ESCAPE_OCTAL            BIT(3)
 66 #define ESCAPE_ANY              \
 67         (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL)
 68 #define ESCAPE_NP               BIT(4)
 69 #define ESCAPE_ANY_NP           (ESCAPE_ANY | ESCAPE_NP)
 70 #define ESCAPE_HEX              BIT(5)
 71 #define ESCAPE_NA               BIT(6)
 72 #define ESCAPE_NAP              BIT(7)
 73 #define ESCAPE_APPEND           BIT(8)
 74 
 75 #define ESCAPE_ALL_MASK         GENMASK(8, 0)
 76 
 77 int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
 78                 unsigned int flags, const char *only);
 79 
 80 static inline int string_escape_mem_any_np(const char *src, size_t isz,
 81                 char *dst, size_t osz, const char *only)
 82 {
 83         return string_escape_mem(src, isz, dst, osz, ESCAPE_ANY_NP, only);
 84 }
 85 
 86 static inline int string_escape_str(const char *src, char *dst, size_t sz,
 87                 unsigned int flags, const char *only)
 88 {
 89         return string_escape_mem(src, strlen(src), dst, sz, flags, only);
 90 }
 91 
 92 static inline int string_escape_str_any_np(const char *src, char *dst,
 93                 size_t sz, const char *only)
 94 {
 95         return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, only);
 96 }
 97 
 98 static inline void string_upper(char *dst, const char *src)
 99 {
100         do {
101                 *dst++ = toupper(*src);
102         } while (*src++);
103 }
104 
105 static inline void string_lower(char *dst, const char *src)
106 {
107         do {
108                 *dst++ = tolower(*src);
109         } while (*src++);
110 }
111 
112 char *kstrdup_quotable(const char *src, gfp_t gfp);
113 char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
114 char *kstrdup_quotable_file(struct file *file, gfp_t gfp);
115 
116 char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp);
117 
118 char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n);
119 void kfree_strarray(char **array, size_t n);
120 
121 char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n);
122 
123 #endif
124 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php