string.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 version
  4. * Copyright IBM Corp. 1999
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  6. */
  7. #ifndef _S390_STRING_H_
  8. #define _S390_STRING_H_
  9. #ifndef _LINUX_TYPES_H
  10. #include <linux/types.h>
  11. #endif
  12. #define __HAVE_ARCH_MEMCHR /* inline & arch function */
  13. #define __HAVE_ARCH_MEMCMP /* arch function */
  14. #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */
  15. #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */
  16. #define __HAVE_ARCH_MEMSCAN /* inline & arch function */
  17. #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */
  18. #define __HAVE_ARCH_MEMSET16 /* arch function */
  19. #define __HAVE_ARCH_MEMSET32 /* arch function */
  20. #define __HAVE_ARCH_MEMSET64 /* arch function */
  21. #define __HAVE_ARCH_STRCAT /* inline & arch function */
  22. #define __HAVE_ARCH_STRCMP /* arch function */
  23. #define __HAVE_ARCH_STRCPY /* inline & arch function */
  24. #define __HAVE_ARCH_STRLCAT /* arch function */
  25. #define __HAVE_ARCH_STRLCPY /* arch function */
  26. #define __HAVE_ARCH_STRLEN /* inline & arch function */
  27. #define __HAVE_ARCH_STRNCAT /* arch function */
  28. #define __HAVE_ARCH_STRNCPY /* arch function */
  29. #define __HAVE_ARCH_STRNLEN /* inline & arch function */
  30. #define __HAVE_ARCH_STRRCHR /* arch function */
  31. #define __HAVE_ARCH_STRSTR /* arch function */
  32. /* Prototypes for non-inlined arch strings functions. */
  33. int memcmp(const void *s1, const void *s2, size_t n);
  34. void *memcpy(void *dest, const void *src, size_t n);
  35. void *memset(void *s, int c, size_t n);
  36. void *memmove(void *dest, const void *src, size_t n);
  37. int strcmp(const char *s1, const char *s2);
  38. size_t strlcat(char *dest, const char *src, size_t n);
  39. size_t strlcpy(char *dest, const char *src, size_t size);
  40. char *strncat(char *dest, const char *src, size_t n);
  41. char *strncpy(char *dest, const char *src, size_t n);
  42. char *strrchr(const char *s, int c);
  43. char *strstr(const char *s1, const char *s2);
  44. #undef __HAVE_ARCH_STRCHR
  45. #undef __HAVE_ARCH_STRNCHR
  46. #undef __HAVE_ARCH_STRNCMP
  47. #undef __HAVE_ARCH_STRPBRK
  48. #undef __HAVE_ARCH_STRSEP
  49. #undef __HAVE_ARCH_STRSPN
  50. void *__memset16(uint16_t *s, uint16_t v, size_t count);
  51. void *__memset32(uint32_t *s, uint32_t v, size_t count);
  52. void *__memset64(uint64_t *s, uint64_t v, size_t count);
  53. static inline void *memset16(uint16_t *s, uint16_t v, size_t count)
  54. {
  55. return __memset16(s, v, count * sizeof(v));
  56. }
  57. static inline void *memset32(uint32_t *s, uint32_t v, size_t count)
  58. {
  59. return __memset32(s, v, count * sizeof(v));
  60. }
  61. static inline void *memset64(uint64_t *s, uint64_t v, size_t count)
  62. {
  63. return __memset64(s, v, count * sizeof(v));
  64. }
  65. #if !defined(IN_ARCH_STRING_C) && (!defined(CONFIG_FORTIFY_SOURCE) || defined(__NO_FORTIFY))
  66. static inline void *memchr(const void * s, int c, size_t n)
  67. {
  68. register int r0 asm("0") = (char) c;
  69. const void *ret = s + n;
  70. asm volatile(
  71. "0: srst %0,%1\n"
  72. " jo 0b\n"
  73. " jl 1f\n"
  74. " la %0,0\n"
  75. "1:"
  76. : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
  77. return (void *) ret;
  78. }
  79. static inline void *memscan(void *s, int c, size_t n)
  80. {
  81. register int r0 asm("0") = (char) c;
  82. const void *ret = s + n;
  83. asm volatile(
  84. "0: srst %0,%1\n"
  85. " jo 0b\n"
  86. : "+a" (ret), "+&a" (s) : "d" (r0) : "cc", "memory");
  87. return (void *) ret;
  88. }
  89. static inline char *strcat(char *dst, const char *src)
  90. {
  91. register int r0 asm("0") = 0;
  92. unsigned long dummy;
  93. char *ret = dst;
  94. asm volatile(
  95. "0: srst %0,%1\n"
  96. " jo 0b\n"
  97. "1: mvst %0,%2\n"
  98. " jo 1b"
  99. : "=&a" (dummy), "+a" (dst), "+a" (src)
  100. : "d" (r0), "0" (0) : "cc", "memory" );
  101. return ret;
  102. }
  103. static inline char *strcpy(char *dst, const char *src)
  104. {
  105. register int r0 asm("0") = 0;
  106. char *ret = dst;
  107. asm volatile(
  108. "0: mvst %0,%1\n"
  109. " jo 0b"
  110. : "+&a" (dst), "+&a" (src) : "d" (r0)
  111. : "cc", "memory");
  112. return ret;
  113. }
  114. static inline size_t strlen(const char *s)
  115. {
  116. register unsigned long r0 asm("0") = 0;
  117. const char *tmp = s;
  118. asm volatile(
  119. "0: srst %0,%1\n"
  120. " jo 0b"
  121. : "+d" (r0), "+a" (tmp) : : "cc", "memory");
  122. return r0 - (unsigned long) s;
  123. }
  124. static inline size_t strnlen(const char * s, size_t n)
  125. {
  126. register int r0 asm("0") = 0;
  127. const char *tmp = s;
  128. const char *end = s + n;
  129. asm volatile(
  130. "0: srst %0,%1\n"
  131. " jo 0b"
  132. : "+a" (end), "+a" (tmp) : "d" (r0) : "cc", "memory");
  133. return end - s;
  134. }
  135. #else /* IN_ARCH_STRING_C */
  136. void *memchr(const void * s, int c, size_t n);
  137. void *memscan(void *s, int c, size_t n);
  138. char *strcat(char *dst, const char *src);
  139. char *strcpy(char *dst, const char *src);
  140. size_t strlen(const char *s);
  141. size_t strnlen(const char * s, size_t n);
  142. #endif /* !IN_ARCH_STRING_C */
  143. #endif /* __S390_STRING_H_ */