string.h 3.9 KB

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