string.h 3.6 KB

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