string.h 3.8 KB

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