blob: 6dfbb2efa81578e9190cdaef8db08140be15dab0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_STRING_H_
3#define _LINUX_STRING_H_
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6#include <linux/compiler.h> /* for inline */
7#include <linux/types.h> /* for size_t */
8#include <linux/stddef.h> /* for NULL */
Lai Jiangshan4370aa42009-03-06 17:21:46 +01009#include <stdarg.h>
David Howells607ca462012-10-13 10:46:48 +010010#include <uapi/linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Davi Arnaut96840aa2006-03-24 03:18:42 -080012extern char *strndup_user(const char __user *, long);
Li Zefan610a77e2009-03-31 15:23:16 -070013extern void *memdup_user(const void __user *, size_t);
Al Viro50fd2f22018-01-07 13:06:15 -050014extern void *vmemdup_user(const void __user *, size_t);
Al Viroe9d408e2015-12-24 00:06:05 -050015extern void *memdup_user_nul(const void __user *, size_t);
Davi Arnaut96840aa2006-03-24 03:18:42 -080016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
18 * Include machine specific inline routines
19 */
20#include <asm/string.h>
21
22#ifndef __HAVE_ARCH_STRCPY
23extern char * strcpy(char *,const char *);
24#endif
25#ifndef __HAVE_ARCH_STRNCPY
26extern char * strncpy(char *,const char *, __kernel_size_t);
27#endif
28#ifndef __HAVE_ARCH_STRLCPY
29size_t strlcpy(char *, const char *, size_t);
30#endif
Chris Metcalf30035e42015-04-29 12:52:04 -040031#ifndef __HAVE_ARCH_STRSCPY
Tejun Heo08a77672018-01-09 07:21:15 -080032ssize_t strscpy(char *, const char *, size_t);
Chris Metcalf30035e42015-04-29 12:52:04 -040033#endif
Tobin C. Harding458a3bf2019-04-05 12:58:58 +110034
35/* Wraps calls to strscpy()/memset(), no arch specific code required */
36ssize_t strscpy_pad(char *dest, const char *src, size_t count);
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#ifndef __HAVE_ARCH_STRCAT
39extern char * strcat(char *, const char *);
40#endif
41#ifndef __HAVE_ARCH_STRNCAT
42extern char * strncat(char *, const char *, __kernel_size_t);
43#endif
44#ifndef __HAVE_ARCH_STRLCAT
45extern size_t strlcat(char *, const char *, __kernel_size_t);
46#endif
47#ifndef __HAVE_ARCH_STRCMP
48extern int strcmp(const char *,const char *);
49#endif
50#ifndef __HAVE_ARCH_STRNCMP
51extern int strncmp(const char *,const char *,__kernel_size_t);
52#endif
David S. Millerded220b2007-03-29 01:18:42 -070053#ifndef __HAVE_ARCH_STRCASECMP
54extern int strcasecmp(const char *s1, const char *s2);
55#endif
56#ifndef __HAVE_ARCH_STRNCASECMP
57extern int strncasecmp(const char *s1, const char *s2, size_t n);
58#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#ifndef __HAVE_ARCH_STRCHR
60extern char * strchr(const char *,int);
61#endif
Grant Likely11d200e2014-03-14 17:00:14 +000062#ifndef __HAVE_ARCH_STRCHRNUL
63extern char * strchrnul(const char *,int);
64#endif
Yury Norov0bee0ce2020-02-03 17:37:20 -080065extern char * strnchrnul(const char *, size_t, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#ifndef __HAVE_ARCH_STRNCHR
67extern char * strnchr(const char *, size_t, int);
68#endif
69#ifndef __HAVE_ARCH_STRRCHR
70extern char * strrchr(const char *,int);
71#endif
André Goddard Rosaf6533982009-12-14 18:01:04 -080072extern char * __must_check skip_spaces(const char *);
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -080073
74extern char *strim(char *);
75
76static inline __must_check char *strstrip(char *str)
77{
78 return strim(str);
79}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#ifndef __HAVE_ARCH_STRSTR
Li Zefand5f1fb52010-01-14 10:53:55 +080082extern char * strstr(const char *, const char *);
83#endif
84#ifndef __HAVE_ARCH_STRNSTR
85extern char * strnstr(const char *, const char *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#endif
87#ifndef __HAVE_ARCH_STRLEN
88extern __kernel_size_t strlen(const char *);
89#endif
90#ifndef __HAVE_ARCH_STRNLEN
91extern __kernel_size_t strnlen(const char *,__kernel_size_t);
92#endif
Kyle McMartin8833d322006-04-10 22:53:57 -070093#ifndef __HAVE_ARCH_STRPBRK
94extern char * strpbrk(const char *,const char *);
95#endif
96#ifndef __HAVE_ARCH_STRSEP
97extern char * strsep(char **,const char *);
98#endif
99#ifndef __HAVE_ARCH_STRSPN
100extern __kernel_size_t strspn(const char *,const char *);
101#endif
102#ifndef __HAVE_ARCH_STRCSPN
103extern __kernel_size_t strcspn(const char *,const char *);
104#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106#ifndef __HAVE_ARCH_MEMSET
107extern void * memset(void *,int,__kernel_size_t);
108#endif
Matthew Wilcox3b3c4ba2017-09-08 16:13:48 -0700109
110#ifndef __HAVE_ARCH_MEMSET16
111extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
112#endif
113
114#ifndef __HAVE_ARCH_MEMSET32
115extern void *memset32(uint32_t *, uint32_t, __kernel_size_t);
116#endif
117
118#ifndef __HAVE_ARCH_MEMSET64
119extern void *memset64(uint64_t *, uint64_t, __kernel_size_t);
120#endif
121
122static inline void *memset_l(unsigned long *p, unsigned long v,
123 __kernel_size_t n)
124{
125 if (BITS_PER_LONG == 32)
126 return memset32((uint32_t *)p, v, n);
127 else
128 return memset64((uint64_t *)p, v, n);
129}
130
131static inline void *memset_p(void **p, void *v, __kernel_size_t n)
132{
133 if (BITS_PER_LONG == 32)
134 return memset32((uint32_t *)p, (uintptr_t)v, n);
135 else
136 return memset64((uint64_t *)p, (uintptr_t)v, n);
137}
138
Alexander Shishkince76d932018-10-05 15:43:05 +0300139extern void **__memcat_p(void **a, void **b);
140#define memcat_p(a, b) ({ \
141 BUILD_BUG_ON_MSG(!__same_type(*(a), *(b)), \
142 "type mismatch in memcat_p()"); \
143 (typeof(*a) *)__memcat_p((void **)(a), (void **)(b)); \
144})
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifndef __HAVE_ARCH_MEMCPY
147extern void * memcpy(void *,const void *,__kernel_size_t);
148#endif
149#ifndef __HAVE_ARCH_MEMMOVE
150extern void * memmove(void *,const void *,__kernel_size_t);
151#endif
152#ifndef __HAVE_ARCH_MEMSCAN
153extern void * memscan(void *,int,__kernel_size_t);
154#endif
155#ifndef __HAVE_ARCH_MEMCMP
156extern int memcmp(const void *,const void *,__kernel_size_t);
157#endif
Nick Desaulniers5f074f32019-04-05 18:38:45 -0700158#ifndef __HAVE_ARCH_BCMP
159extern int bcmp(const void *,const void *,__kernel_size_t);
160#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#ifndef __HAVE_ARCH_MEMCHR
162extern void * memchr(const void *,int,__kernel_size_t);
163#endif
Dan Williams6abccd12017-01-13 14:14:23 -0800164#ifndef __HAVE_ARCH_MEMCPY_MCSAFE
Dan Williams60622d62018-05-03 17:06:21 -0700165static inline __must_check unsigned long memcpy_mcsafe(void *dst,
166 const void *src, size_t cnt)
Dan Williams6abccd12017-01-13 14:14:23 -0800167{
168 memcpy(dst, src, cnt);
169 return 0;
170}
171#endif
Dan Williams0aed55a2017-05-29 12:22:50 -0700172#ifndef __HAVE_ARCH_MEMCPY_FLUSHCACHE
173static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
174{
175 memcpy(dst, src, cnt);
176}
177#endif
Akinobu Mita798248202011-10-31 17:08:07 -0700178void *memchr_inv(const void *s, int c, size_t n);
Rasmus Villemoes94df2902015-06-25 15:02:22 -0700179char *strreplace(char *s, char old, char new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Andrzej Hajdaa4bb1e42015-02-13 14:36:24 -0800181extern void kfree_const(const void *x);
182
Rasmus Villemoes48a270552016-05-19 17:10:55 -0700183extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
Andrzej Hajdaa4bb1e42015-02-13 14:36:24 -0800184extern const char *kstrdup_const(const char *s, gfp_t gfp);
Jeremy Fitzhardinge1e66df32007-07-17 18:37:02 -0700185extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
Alexey Dobriyan1a2f67b2006-09-30 23:27:20 -0700186extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
David Howellsf3515742017-07-04 17:25:02 +0100187extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
Paulo Marques543537b2005-06-23 00:09:02 -0700188
Jeremy Fitzhardinged84d1cc2007-07-17 18:37:02 -0700189extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
190extern void argv_free(char **argv);
191
David Brownell34990cf2008-05-01 04:34:42 -0700192extern bool sysfs_streq(const char *s1, const char *s2);
Kees Cookef951592016-03-17 14:22:50 -0700193extern int kstrtobool(const char *s, bool *res);
194static inline int strtobool(const char *s, bool *res)
195{
196 return kstrtobool(s, res);
197}
David Brownell34990cf2008-05-01 04:34:42 -0700198
Andy Shevchenko56b06082016-03-17 14:22:14 -0700199int match_string(const char * const *array, size_t n, const char *string);
Heikki Krogeruse1fe7b62017-03-21 13:56:46 +0200200int __sysfs_match_string(const char * const *array, size_t n, const char *s);
201
202/**
203 * sysfs_match_string - matches given string in an array
204 * @_a: array of strings
205 * @_s: string to match with
206 *
207 * Helper for __sysfs_match_string(). Calculates the size of @a automatically.
208 */
209#define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
Andy Shevchenko56b06082016-03-17 14:22:14 -0700210
Lai Jiangshan4370aa42009-03-06 17:21:46 +0100211#ifdef CONFIG_BINARY_PRINTF
212int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
213int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
214int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
215#endif
216
Akinobu Mitae108526e2008-07-23 21:26:44 -0700217extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
Daniel Borkmannd4c5efd2014-08-26 23:16:35 -0400218 const void *from, size_t available);
Akinobu Mitae108526e2008-07-23 21:26:44 -0700219
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800220int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
221
Rusty Russell66f92cf2009-03-31 13:05:36 -0600222/**
223 * strstarts - does @str start with @prefix?
224 * @str: string to examine
225 * @prefix: prefix to look for.
226 */
227static inline bool strstarts(const char *str, const char *prefix)
228{
229 return strncmp(str, prefix, strlen(prefix)) == 0;
230}
Akinobu Mita639b9e32012-07-30 14:40:55 -0700231
Daniel Borkmannd4c5efd2014-08-26 23:16:35 -0400232size_t memweight(const void *ptr, size_t bytes);
Arvind Sankarbec50072019-10-07 18:00:02 -0400233
234/**
235 * memzero_explicit - Fill a region of memory (e.g. sensitive
236 * keying data) with 0s.
237 * @s: Pointer to the start of the area.
238 * @count: The size of the area.
239 *
240 * Note: usually using memset() is just fine (!), but in cases
241 * where clearing out _local_ data at the end of a scope is
242 * necessary, memzero_explicit() should be used instead in
243 * order to prevent the compiler from optimising away zeroing.
244 *
245 * memzero_explicit() doesn't need an arch-specific version as
246 * it just invokes the one of memset() implicitly.
247 */
248static inline void memzero_explicit(void *s, size_t count)
249{
250 memset(s, 0, count);
251 barrier_data(s);
252}
Akinobu Mita639b9e32012-07-30 14:40:55 -0700253
Andy Shevchenkob18888a2012-12-17 16:01:18 -0800254/**
255 * kbasename - return the last part of a pathname.
256 *
257 * @path: path to extract the filename from.
258 */
259static inline const char *kbasename(const char *path)
260{
261 const char *tail = strrchr(path, '/');
262 return tail ? tail + 1 : path;
263}
264
Daniel Micay6974f0c2017-07-12 14:36:10 -0700265#define __FORTIFY_INLINE extern __always_inline __attribute__((gnu_inline))
266#define __RENAME(x) __asm__(#x)
267
268void fortify_panic(const char *name) __noreturn __cold;
269void __read_overflow(void) __compiletime_error("detected read beyond size of object passed as 1st parameter");
270void __read_overflow2(void) __compiletime_error("detected read beyond size of object passed as 2nd parameter");
Martin Wilck01f33c32017-08-14 22:12:38 +0200271void __read_overflow3(void) __compiletime_error("detected read beyond size of object passed as 3rd parameter");
Daniel Micay6974f0c2017-07-12 14:36:10 -0700272void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
273
274#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
Daniel Micay6974f0c2017-07-12 14:36:10 -0700275__FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
276{
277 size_t p_size = __builtin_object_size(p, 0);
278 if (__builtin_constant_p(size) && p_size < size)
279 __write_overflow();
280 if (p_size < size)
281 fortify_panic(__func__);
282 return __builtin_strncpy(p, q, size);
283}
284
285__FORTIFY_INLINE char *strcat(char *p, const char *q)
286{
287 size_t p_size = __builtin_object_size(p, 0);
288 if (p_size == (size_t)-1)
289 return __builtin_strcat(p, q);
290 if (strlcat(p, q, p_size) >= p_size)
291 fortify_panic(__func__);
292 return p;
293}
294
295__FORTIFY_INLINE __kernel_size_t strlen(const char *p)
296{
297 __kernel_size_t ret;
298 size_t p_size = __builtin_object_size(p, 0);
Arnd Bergmann146734b2017-12-14 15:32:34 -0800299
300 /* Work around gcc excess stack consumption issue */
301 if (p_size == (size_t)-1 ||
302 (__builtin_constant_p(p[p_size - 1]) && p[p_size - 1] == '\0'))
Daniel Micay6974f0c2017-07-12 14:36:10 -0700303 return __builtin_strlen(p);
304 ret = strnlen(p, p_size);
305 if (p_size <= ret)
306 fortify_panic(__func__);
307 return ret;
308}
309
310extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen);
311__FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen)
312{
313 size_t p_size = __builtin_object_size(p, 0);
314 __kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
315 if (p_size <= ret && maxlen != ret)
316 fortify_panic(__func__);
317 return ret;
318}
319
320/* defined after fortified strlen to reuse it */
321extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
322__FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
323{
324 size_t ret;
325 size_t p_size = __builtin_object_size(p, 0);
326 size_t q_size = __builtin_object_size(q, 0);
327 if (p_size == (size_t)-1 && q_size == (size_t)-1)
328 return __real_strlcpy(p, q, size);
329 ret = strlen(q);
330 if (size) {
331 size_t len = (ret >= size) ? size - 1 : ret;
332 if (__builtin_constant_p(len) && len >= p_size)
333 __write_overflow();
334 if (len >= p_size)
335 fortify_panic(__func__);
336 __builtin_memcpy(p, q, len);
337 p[len] = '\0';
338 }
339 return ret;
340}
341
342/* defined after fortified strlen and strnlen to reuse them */
343__FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
344{
345 size_t p_len, copy_len;
346 size_t p_size = __builtin_object_size(p, 0);
347 size_t q_size = __builtin_object_size(q, 0);
348 if (p_size == (size_t)-1 && q_size == (size_t)-1)
349 return __builtin_strncat(p, q, count);
350 p_len = strlen(p);
351 copy_len = strnlen(q, count);
352 if (p_size < p_len + copy_len + 1)
353 fortify_panic(__func__);
354 __builtin_memcpy(p + p_len, q, copy_len);
355 p[p_len + copy_len] = '\0';
356 return p;
357}
358
359__FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size)
360{
361 size_t p_size = __builtin_object_size(p, 0);
362 if (__builtin_constant_p(size) && p_size < size)
363 __write_overflow();
364 if (p_size < size)
365 fortify_panic(__func__);
366 return __builtin_memset(p, c, size);
367}
368
369__FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
370{
371 size_t p_size = __builtin_object_size(p, 0);
372 size_t q_size = __builtin_object_size(q, 0);
373 if (__builtin_constant_p(size)) {
374 if (p_size < size)
375 __write_overflow();
376 if (q_size < size)
377 __read_overflow2();
378 }
379 if (p_size < size || q_size < size)
380 fortify_panic(__func__);
381 return __builtin_memcpy(p, q, size);
382}
383
384__FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size)
385{
386 size_t p_size = __builtin_object_size(p, 0);
387 size_t q_size = __builtin_object_size(q, 0);
388 if (__builtin_constant_p(size)) {
389 if (p_size < size)
390 __write_overflow();
391 if (q_size < size)
392 __read_overflow2();
393 }
394 if (p_size < size || q_size < size)
395 fortify_panic(__func__);
396 return __builtin_memmove(p, q, size);
397}
398
399extern void *__real_memscan(void *, int, __kernel_size_t) __RENAME(memscan);
400__FORTIFY_INLINE void *memscan(void *p, int c, __kernel_size_t size)
401{
402 size_t p_size = __builtin_object_size(p, 0);
403 if (__builtin_constant_p(size) && p_size < size)
404 __read_overflow();
405 if (p_size < size)
406 fortify_panic(__func__);
407 return __real_memscan(p, c, size);
408}
409
410__FORTIFY_INLINE int memcmp(const void *p, const void *q, __kernel_size_t size)
411{
412 size_t p_size = __builtin_object_size(p, 0);
413 size_t q_size = __builtin_object_size(q, 0);
414 if (__builtin_constant_p(size)) {
415 if (p_size < size)
416 __read_overflow();
417 if (q_size < size)
418 __read_overflow2();
419 }
420 if (p_size < size || q_size < size)
421 fortify_panic(__func__);
422 return __builtin_memcmp(p, q, size);
423}
424
425__FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)
426{
427 size_t p_size = __builtin_object_size(p, 0);
428 if (__builtin_constant_p(size) && p_size < size)
429 __read_overflow();
430 if (p_size < size)
431 fortify_panic(__func__);
432 return __builtin_memchr(p, c, size);
433}
434
435void *__real_memchr_inv(const void *s, int c, size_t n) __RENAME(memchr_inv);
436__FORTIFY_INLINE void *memchr_inv(const void *p, int c, size_t size)
437{
438 size_t p_size = __builtin_object_size(p, 0);
439 if (__builtin_constant_p(size) && p_size < size)
440 __read_overflow();
441 if (p_size < size)
442 fortify_panic(__func__);
443 return __real_memchr_inv(p, c, size);
444}
445
446extern void *__real_kmemdup(const void *src, size_t len, gfp_t gfp) __RENAME(kmemdup);
447__FORTIFY_INLINE void *kmemdup(const void *p, size_t size, gfp_t gfp)
448{
449 size_t p_size = __builtin_object_size(p, 0);
450 if (__builtin_constant_p(size) && p_size < size)
451 __read_overflow();
452 if (p_size < size)
453 fortify_panic(__func__);
454 return __real_kmemdup(p, size, gfp);
455}
Daniel Micay077d2ba2017-07-14 17:28:12 -0400456
457/* defined after fortified strlen and memcpy to reuse them */
458__FORTIFY_INLINE char *strcpy(char *p, const char *q)
459{
460 size_t p_size = __builtin_object_size(p, 0);
461 size_t q_size = __builtin_object_size(q, 0);
462 if (p_size == (size_t)-1 && q_size == (size_t)-1)
463 return __builtin_strcpy(p, q);
464 memcpy(p, q, strlen(q) + 1);
465 return p;
466}
467
Daniel Micay6974f0c2017-07-12 14:36:10 -0700468#endif
469
Martin Wilck01f33c32017-08-14 22:12:38 +0200470/**
471 * memcpy_and_pad - Copy one buffer to another with padding
472 * @dest: Where to copy to
473 * @dest_len: The destination buffer size
474 * @src: Where to copy from
475 * @count: The number of bytes to copy
476 * @pad: Character to use for padding if space is left in destination.
477 */
Martin Wilck13597982017-09-06 14:36:57 +0200478static inline void memcpy_and_pad(void *dest, size_t dest_len,
479 const void *src, size_t count, int pad)
Martin Wilck01f33c32017-08-14 22:12:38 +0200480{
Martin Wilck01f33c32017-08-14 22:12:38 +0200481 if (dest_len > count) {
482 memcpy(dest, src, count);
483 memset(dest + count, pad, dest_len - count);
484 } else
485 memcpy(dest, src, dest_len);
486}
487
Steven Rostedt (VMware)72921422018-12-21 18:10:14 -0500488/**
489 * str_has_prefix - Test if a string has a given prefix
490 * @str: The string to test
491 * @prefix: The string to see if @str starts with
492 *
493 * A common way to test a prefix of a string is to do:
494 * strncmp(str, prefix, sizeof(prefix) - 1)
495 *
496 * But this can lead to bugs due to typos, or if prefix is a pointer
497 * and not a constant. Instead use str_has_prefix().
498 *
Joe Perches917cda22019-09-25 16:46:13 -0700499 * Returns:
500 * * strlen(@prefix) if @str starts with @prefix
501 * * 0 if @str does not start with @prefix
Steven Rostedt (VMware)72921422018-12-21 18:10:14 -0500502 */
503static __always_inline size_t str_has_prefix(const char *str, const char *prefix)
504{
505 size_t len = strlen(prefix);
506 return strncmp(str, prefix, len) == 0 ? len : 0;
507}
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#endif /* _LINUX_STRING_H_ */