string.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef __ASM_SH_STRING_H
  2. #define __ASM_SH_STRING_H
  3. /*
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * But consider these trivial functions to be public domain.
  6. *
  7. * from linux kernel code.
  8. */
  9. #ifdef __KERNEL__ /* only set these up for kernel code */
  10. #define __HAVE_ARCH_STRCPY
  11. static inline char *strcpy(char *__dest, const char *__src)
  12. {
  13. register char *__xdest = __dest;
  14. unsigned long __dummy;
  15. __asm__ __volatile__("1:\n\t"
  16. "mov.b @%1+, %2\n\t"
  17. "mov.b %2, @%0\n\t"
  18. "cmp/eq #0, %2\n\t"
  19. "bf/s 1b\n\t"
  20. " add #1, %0\n\t"
  21. : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
  22. : "0" (__dest), "1" (__src)
  23. : "memory", "t");
  24. return __xdest;
  25. }
  26. #define __HAVE_ARCH_STRNCPY
  27. static inline char *strncpy(char *__dest, const char *__src, size_t __n)
  28. {
  29. register char *__xdest = __dest;
  30. unsigned long __dummy;
  31. if (__n == 0)
  32. return __xdest;
  33. __asm__ __volatile__(
  34. "1:\n"
  35. "mov.b @%1+, %2\n\t"
  36. "mov.b %2, @%0\n\t"
  37. "cmp/eq #0, %2\n\t"
  38. "bt/s 2f\n\t"
  39. " cmp/eq %5,%1\n\t"
  40. "bf/s 1b\n\t"
  41. " add #1, %0\n"
  42. "2:"
  43. : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
  44. : "0" (__dest), "1" (__src), "r" (__src+__n)
  45. : "memory", "t");
  46. return __xdest;
  47. }
  48. #define __HAVE_ARCH_STRCMP
  49. static inline int strcmp(const char *__cs, const char *__ct)
  50. {
  51. register int __res;
  52. unsigned long __dummy;
  53. __asm__ __volatile__(
  54. "mov.b @%1+, %3\n"
  55. "1:\n\t"
  56. "mov.b @%0+, %2\n\t"
  57. "cmp/eq #0, %3\n\t"
  58. "bt 2f\n\t"
  59. "cmp/eq %2, %3\n\t"
  60. "bt/s 1b\n\t"
  61. " mov.b @%1+, %3\n\t"
  62. "add #-2, %1\n\t"
  63. "mov.b @%1, %3\n\t"
  64. "sub %3, %2\n"
  65. "2:"
  66. : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
  67. : "0" (__cs), "1" (__ct)
  68. : "t");
  69. return __res;
  70. }
  71. #undef __HAVE_ARCH_STRNCMP
  72. extern int strncmp(const char *__cs, const char *__ct, size_t __n);
  73. #undef __HAVE_ARCH_MEMSET
  74. extern void *memset(void *__s, int __c, size_t __count);
  75. #undef __HAVE_ARCH_MEMCPY
  76. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  77. #undef __HAVE_ARCH_MEMMOVE
  78. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  79. #undef __HAVE_ARCH_MEMCHR
  80. extern void *memchr(const void *__s, int __c, size_t __n);
  81. #undef __HAVE_ARCH_STRLEN
  82. extern size_t strlen(const char *);
  83. /* arch/sh/lib/strcasecmp.c */
  84. extern int strcasecmp(const char *, const char *);
  85. #else /* KERNEL */
  86. /*
  87. * let user libraries deal with these,
  88. * IMHO the kernel has no place defining these functions for user apps
  89. */
  90. #define __HAVE_ARCH_STRCPY 1
  91. #define __HAVE_ARCH_STRNCPY 1
  92. #define __HAVE_ARCH_STRCAT 1
  93. #define __HAVE_ARCH_STRNCAT 1
  94. #define __HAVE_ARCH_STRCMP 1
  95. #define __HAVE_ARCH_STRNCMP 1
  96. #define __HAVE_ARCH_STRNICMP 1
  97. #define __HAVE_ARCH_STRCHR 1
  98. #define __HAVE_ARCH_STRRCHR 1
  99. #define __HAVE_ARCH_STRSTR 1
  100. #define __HAVE_ARCH_STRLEN 1
  101. #define __HAVE_ARCH_STRNLEN 1
  102. #define __HAVE_ARCH_MEMSET 1
  103. #define __HAVE_ARCH_MEMCPY 1
  104. #define __HAVE_ARCH_MEMMOVE 1
  105. #define __HAVE_ARCH_MEMSCAN 1
  106. #define __HAVE_ARCH_MEMCMP 1
  107. #define __HAVE_ARCH_MEMCHR 1
  108. #define __HAVE_ARCH_STRTOK 1
  109. #endif /* KERNEL */
  110. #endif /* __ASM_SH_STRING_H */