string.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef _LINUX_STRING_H_
  2. #define _LINUX_STRING_H_
  3. #include <linux/compiler.h> /* for inline */
  4. #include <linux/types.h> /* for size_t */
  5. #include <linux/stddef.h> /* for NULL */
  6. #include <stdarg.h>
  7. #include <uapi/linux/string.h>
  8. extern char *strndup_user(const char __user *, long);
  9. extern void *memdup_user(const void __user *, size_t);
  10. /*
  11. * Include machine specific inline routines
  12. */
  13. #include <asm/string.h>
  14. #ifndef __HAVE_ARCH_STRCPY
  15. extern char * strcpy(char *,const char *);
  16. #endif
  17. #ifndef __HAVE_ARCH_STRNCPY
  18. extern char * strncpy(char *,const char *, __kernel_size_t);
  19. #endif
  20. #ifndef __HAVE_ARCH_STRLCPY
  21. size_t strlcpy(char *, const char *, size_t);
  22. #endif
  23. #ifndef __HAVE_ARCH_STRSCPY
  24. ssize_t strscpy(char *, const char *, size_t);
  25. #endif
  26. #ifndef __HAVE_ARCH_STRCAT
  27. extern char * strcat(char *, const char *);
  28. #endif
  29. #ifndef __HAVE_ARCH_STRNCAT
  30. extern char * strncat(char *, const char *, __kernel_size_t);
  31. #endif
  32. #ifndef __HAVE_ARCH_STRLCAT
  33. extern size_t strlcat(char *, const char *, __kernel_size_t);
  34. #endif
  35. #ifndef __HAVE_ARCH_STRCMP
  36. extern int strcmp(const char *,const char *);
  37. #endif
  38. #ifndef __HAVE_ARCH_STRNCMP
  39. extern int strncmp(const char *,const char *,__kernel_size_t);
  40. #endif
  41. #ifndef __HAVE_ARCH_STRCASECMP
  42. extern int strcasecmp(const char *s1, const char *s2);
  43. #endif
  44. #ifndef __HAVE_ARCH_STRNCASECMP
  45. extern int strncasecmp(const char *s1, const char *s2, size_t n);
  46. #endif
  47. #ifndef __HAVE_ARCH_STRCHR
  48. extern char * strchr(const char *,int);
  49. #endif
  50. #ifndef __HAVE_ARCH_STRCHRNUL
  51. extern char * strchrnul(const char *,int);
  52. #endif
  53. #ifndef __HAVE_ARCH_STRNCHR
  54. extern char * strnchr(const char *, size_t, int);
  55. #endif
  56. #ifndef __HAVE_ARCH_STRRCHR
  57. extern char * strrchr(const char *,int);
  58. #endif
  59. extern char * __must_check skip_spaces(const char *);
  60. extern char *strim(char *);
  61. static inline __must_check char *strstrip(char *str)
  62. {
  63. return strim(str);
  64. }
  65. #ifndef __HAVE_ARCH_STRSTR
  66. extern char * strstr(const char *, const char *);
  67. #endif
  68. #ifndef __HAVE_ARCH_STRNSTR
  69. extern char * strnstr(const char *, const char *, size_t);
  70. #endif
  71. #ifndef __HAVE_ARCH_STRLEN
  72. extern __kernel_size_t strlen(const char *);
  73. #endif
  74. #ifndef __HAVE_ARCH_STRNLEN
  75. extern __kernel_size_t strnlen(const char *,__kernel_size_t);
  76. #endif
  77. #ifndef __HAVE_ARCH_STRPBRK
  78. extern char * strpbrk(const char *,const char *);
  79. #endif
  80. #ifndef __HAVE_ARCH_STRSEP
  81. extern char * strsep(char **,const char *);
  82. #endif
  83. #ifndef __HAVE_ARCH_STRSPN
  84. extern __kernel_size_t strspn(const char *,const char *);
  85. #endif
  86. #ifndef __HAVE_ARCH_STRCSPN
  87. extern __kernel_size_t strcspn(const char *,const char *);
  88. #endif
  89. #ifndef __HAVE_ARCH_MEMSET
  90. extern void * memset(void *,int,__kernel_size_t);
  91. #endif
  92. #ifndef __HAVE_ARCH_MEMCPY
  93. extern void * memcpy(void *,const void *,__kernel_size_t);
  94. #endif
  95. #ifndef __HAVE_ARCH_MEMMOVE
  96. extern void * memmove(void *,const void *,__kernel_size_t);
  97. #endif
  98. #ifndef __HAVE_ARCH_MEMSCAN
  99. extern void * memscan(void *,int,__kernel_size_t);
  100. #endif
  101. #ifndef __HAVE_ARCH_MEMCMP
  102. extern int memcmp(const void *,const void *,__kernel_size_t);
  103. #endif
  104. #ifndef __HAVE_ARCH_BCMP
  105. extern int bcmp(const void *,const void *,__kernel_size_t);
  106. #endif
  107. #ifndef __HAVE_ARCH_MEMCHR
  108. extern void * memchr(const void *,int,__kernel_size_t);
  109. #endif
  110. void *memchr_inv(const void *s, int c, size_t n);
  111. char *strreplace(char *s, char old, char new);
  112. extern void kfree_const(const void *x);
  113. extern char *kstrdup(const char *s, gfp_t gfp);
  114. extern const char *kstrdup_const(const char *s, gfp_t gfp);
  115. extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
  116. extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
  117. extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
  118. extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
  119. extern void argv_free(char **argv);
  120. extern bool sysfs_streq(const char *s1, const char *s2);
  121. extern int kstrtobool(const char *s, bool *res);
  122. static inline int strtobool(const char *s, bool *res)
  123. {
  124. return kstrtobool(s, res);
  125. }
  126. #ifdef CONFIG_BINARY_PRINTF
  127. int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
  128. int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
  129. int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
  130. #endif
  131. extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
  132. const void *from, size_t available);
  133. /**
  134. * strstarts - does @str start with @prefix?
  135. * @str: string to examine
  136. * @prefix: prefix to look for.
  137. */
  138. static inline bool strstarts(const char *str, const char *prefix)
  139. {
  140. return strncmp(str, prefix, strlen(prefix)) == 0;
  141. }
  142. size_t memweight(const void *ptr, size_t bytes);
  143. void memzero_explicit(void *s, size_t count);
  144. /**
  145. * kbasename - return the last part of a pathname.
  146. *
  147. * @path: path to extract the filename from.
  148. */
  149. static inline const char *kbasename(const char *path)
  150. {
  151. const char *tail = strrchr(path, '/');
  152. return tail ? tail + 1 : path;
  153. }
  154. #endif /* _LINUX_STRING_H_ */