string.h 4.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
#ifndef _LINUX_STRING_H_
#define _LINUX_STRING_H_


#include <linux/compiler.h>	/* for inline */
#include <linux/types.h>	/* for size_t */
#include <linux/stddef.h>	/* for NULL */
L
Lai Jiangshan 已提交
8
#include <stdarg.h>
9
#include <uapi/linux/string.h>
L
Linus Torvalds 已提交
10

D
Davi Arnaut 已提交
11
extern char *strndup_user(const char __user *, long);
L
Li Zefan 已提交
12
extern void *memdup_user(const void __user *, size_t);
A
Al Viro 已提交
13
extern void *memdup_user_nul(const void __user *, size_t);
D
Davi Arnaut 已提交
14

L
Linus Torvalds 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Include machine specific inline routines
 */
#include <asm/string.h>

#ifndef __HAVE_ARCH_STRCPY
extern char * strcpy(char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRNCPY
extern char * strncpy(char *,const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif
C
Chris Metcalf 已提交
29 30 31
#ifndef __HAVE_ARCH_STRSCPY
ssize_t __must_check strscpy(char *, const char *, size_t);
#endif
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#ifndef __HAVE_ARCH_STRCAT
extern char * strcat(char *, const char *);
#endif
#ifndef __HAVE_ARCH_STRNCAT
extern char * strncat(char *, const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRLCAT
extern size_t strlcat(char *, const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRCMP
extern int strcmp(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
47 48 49 50 51 52
#ifndef __HAVE_ARCH_STRCASECMP
extern int strcasecmp(const char *s1, const char *s2);
#endif
#ifndef __HAVE_ARCH_STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
L
Linus Torvalds 已提交
53 54 55
#ifndef __HAVE_ARCH_STRCHR
extern char * strchr(const char *,int);
#endif
56 57 58
#ifndef __HAVE_ARCH_STRCHRNUL
extern char * strchrnul(const char *,int);
#endif
L
Linus Torvalds 已提交
59 60 61 62 63 64
#ifndef __HAVE_ARCH_STRNCHR
extern char * strnchr(const char *, size_t, int);
#endif
#ifndef __HAVE_ARCH_STRRCHR
extern char * strrchr(const char *,int);
#endif
65
extern char * __must_check skip_spaces(const char *);
66 67 68 69 70 71 72 73

extern char *strim(char *);

static inline __must_check char *strstrip(char *str)
{
	return strim(str);
}

L
Linus Torvalds 已提交
74
#ifndef __HAVE_ARCH_STRSTR
L
Li Zefan 已提交
75 76 77 78
extern char * strstr(const char *, const char *);
#endif
#ifndef __HAVE_ARCH_STRNSTR
extern char * strnstr(const char *, const char *, size_t);
L
Linus Torvalds 已提交
79 80 81 82 83 84 85
#endif
#ifndef __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *);
#endif
#ifndef __HAVE_ARCH_STRNLEN
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
#endif
86 87 88 89 90 91 92 93 94 95 96 97
#ifndef __HAVE_ARCH_STRPBRK
extern char * strpbrk(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRSEP
extern char * strsep(char **,const char *);
#endif
#ifndef __HAVE_ARCH_STRSPN
extern __kernel_size_t strspn(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRCSPN
extern __kernel_size_t strcspn(const char *,const char *);
#endif
L
Linus Torvalds 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

#ifndef __HAVE_ARCH_MEMSET
extern void * memset(void *,int,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCPY
extern void * memcpy(void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMMOVE
extern void * memmove(void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMSCAN
extern void * memscan(void *,int,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCMP
extern int memcmp(const void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCHR
extern void * memchr(const void *,int,__kernel_size_t);
#endif
117
void *memchr_inv(const void *s, int c, size_t n);
118
char *strreplace(char *s, char old, char new);
L
Linus Torvalds 已提交
119

A
Andrzej Hajda 已提交
120 121
extern void kfree_const(const void *x);

122
extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
A
Andrzej Hajda 已提交
123
extern const char *kstrdup_const(const char *s, gfp_t gfp);
J
Jeremy Fitzhardinge 已提交
124
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
A
Alexey Dobriyan 已提交
125
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
126

J
Jeremy Fitzhardinge 已提交
127 128 129
extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
extern void argv_free(char **argv);

130
extern bool sysfs_streq(const char *s1, const char *s2);
131 132 133 134 135
extern int kstrtobool(const char *s, bool *res);
static inline int strtobool(const char *s, bool *res)
{
	return kstrtobool(s, res);
}
136

137 138
int match_string(const char * const *array, size_t n, const char *string);

L
Lai Jiangshan 已提交
139 140 141 142 143 144
#ifdef CONFIG_BINARY_PRINTF
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
#endif

145
extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
146
				       const void *from, size_t available);
147

148 149 150 151 152 153 154 155 156
/**
 * strstarts - does @str start with @prefix?
 * @str: string to examine
 * @prefix: prefix to look for.
 */
static inline bool strstarts(const char *str, const char *prefix)
{
	return strncmp(str, prefix, strlen(prefix)) == 0;
}
A
Akinobu Mita 已提交
157

158 159
size_t memweight(const void *ptr, size_t bytes);
void memzero_explicit(void *s, size_t count);
A
Akinobu Mita 已提交
160

161 162 163 164 165 166 167 168 169 170 171
/**
 * kbasename - return the last part of a pathname.
 *
 * @path: path to extract the filename from.
 */
static inline const char *kbasename(const char *path)
{
	const char *tail = strrchr(path, '/');
	return tail ? tail + 1 : path;
}

L
Linus Torvalds 已提交
172
#endif /* _LINUX_STRING_H_ */