string.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ALPHA_STRING_H__
  3. #define __ALPHA_STRING_H__
  4. #ifdef __KERNEL__
  5. /*
  6. * GCC of any recent vintage doesn't do stupid things with bcopy.
  7. * EGCS 1.1 knows all about expanding memcpy inline, others don't.
  8. *
  9. * Similarly for a memset with data = 0.
  10. */
  11. #define __HAVE_ARCH_MEMCPY
  12. extern void * memcpy(void *, const void *, size_t);
  13. #define __HAVE_ARCH_MEMMOVE
  14. extern void * memmove(void *, const void *, size_t);
  15. /* For backward compatibility with modules. Unused otherwise. */
  16. extern void * __memcpy(void *, const void *, size_t);
  17. #define memcpy __builtin_memcpy
  18. #define __HAVE_ARCH_MEMSET
  19. extern void * __constant_c_memset(void *, unsigned long, size_t);
  20. extern void * ___memset(void *, int, size_t);
  21. extern void * __memset(void *, int, size_t);
  22. extern void * memset(void *, int, size_t);
  23. /* For gcc 3.x, we cannot have the inline function named "memset" because
  24. the __builtin_memset will attempt to resolve to the inline as well,
  25. leading to a "sorry" about unimplemented recursive inlining. */
  26. extern inline void *__memset(void *s, int c, size_t n)
  27. {
  28. if (__builtin_constant_p(c)) {
  29. if (__builtin_constant_p(n)) {
  30. return __builtin_memset(s, c, n);
  31. } else {
  32. unsigned long c8 = (c & 0xff) * 0x0101010101010101UL;
  33. return __constant_c_memset(s, c8, n);
  34. }
  35. }
  36. return ___memset(s, c, n);
  37. }
  38. #define memset __memset
  39. #define __HAVE_ARCH_STRCPY
  40. extern char * strcpy(char *,const char *);
  41. #define __HAVE_ARCH_STRNCPY
  42. extern char * strncpy(char *, const char *, size_t);
  43. #define __HAVE_ARCH_STRCAT
  44. extern char * strcat(char *, const char *);
  45. #define __HAVE_ARCH_STRNCAT
  46. extern char * strncat(char *, const char *, size_t);
  47. #define __HAVE_ARCH_STRCHR
  48. extern char * strchr(const char *,int);
  49. #define __HAVE_ARCH_STRRCHR
  50. extern char * strrchr(const char *,int);
  51. #define __HAVE_ARCH_STRLEN
  52. extern size_t strlen(const char *);
  53. #define __HAVE_ARCH_MEMCHR
  54. extern void * memchr(const void *, int, size_t);
  55. /* The following routine is like memset except that it writes 16-bit
  56. aligned values. The DEST and COUNT parameters must be even for
  57. correct operation. */
  58. #define __HAVE_ARCH_MEMSET16
  59. extern void * __memset16(void *dest, unsigned short, size_t count);
  60. static inline void *memset16(uint16_t *p, uint16_t v, size_t n)
  61. {
  62. if (__builtin_constant_p(v))
  63. return __constant_c_memset(p, 0x0001000100010001UL * v, n * 2);
  64. return __memset16(p, v, n * 2);
  65. }
  66. #endif /* __KERNEL__ */
  67. #endif /* __ALPHA_STRING_H__ */