string.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*-------------------------------------------------------------------------
  2. string.h - ISO header for string library functions
  3. Copyright (C) 1998, Sandeep Dutta
  4. Copyright (C) 2009-2011, Philipp Klaus Krause pkk@spth.de
  5. This library is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option) any
  8. later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this library; see the file COPYING. If not, write to the
  15. Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02110-1301, USA.
  17. As a special exception, if you link this library with other files,
  18. some of which are compiled with SDCC, to produce an executable,
  19. this library does not by itself cause the resulting executable to
  20. be covered by the GNU General Public License. This exception does
  21. not however invalidate any other reasons why the executable file
  22. might be covered by the GNU General Public License.
  23. -------------------------------------------------------------------------*/
  24. #ifndef __SDCC_STRING_H
  25. #define __SDCC_STRING_H 1
  26. #ifndef NULL
  27. # define NULL (void *)0
  28. #endif
  29. #ifndef __SIZE_T_DEFINED
  30. # define __SIZE_T_DEFINED
  31. typedef unsigned int size_t;
  32. #endif
  33. /* Bounds-checking interfaces from annex K of the C11 standard. */
  34. #if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__
  35. #ifndef __RSIZE_T_DEFINED
  36. #define __RSIZE_T_DEFINED
  37. typedef size_t rsize_t;
  38. #endif
  39. #ifndef __ERRNO_T_DEFINED
  40. #define __ERRNO_T_DEFINED
  41. typedef int errno_t;
  42. #endif
  43. #endif
  44. #if defined(__SDCC_mcs51) || defined(__SDCC_hc08) || defined(__SDCC_ds390) || defined(__SDCC_pic14) || defined(__SDCC_pic16)
  45. #define __SDCC_BROKEN_STRING_FUNCTIONS
  46. #endif
  47. /* The function prototypes are ordered as in the ISO C99 standard. */
  48. /* Todo: fix the "restrict" stuff for C99 compliance. */
  49. /* Copying functions: */
  50. extern void *memcpy (void * /*restrict */ dest, const void * /*restrict*/ src, size_t n);
  51. extern void *memmove (void *dest, const void *src, size_t n);
  52. extern char *strcpy (char * /*restrict*/ dest, const char * /*restrict*/ src);
  53. extern char *strncpy(char * /*restrict*/ dest, const char * /*restrict*/ src, size_t n);
  54. /* Concatenation functions: */
  55. extern char *strcat (char * /*restrict*/ dest, const char * /*restrict*/ src);
  56. extern char *strncat(char * /*restrict*/ dest, const char * /*restrict*/ src, size_t n);
  57. /* Comparison functions: */
  58. extern int memcmp (const void *s1, const void *s2, size_t n);
  59. extern int strcmp (const char *s1, const char *s2);
  60. #define strcoll(s1, s2) strcmp(s1, s2)
  61. /*int strcoll(const char *s1, const char *s2) {return strcmp(s1, s2);}*/
  62. extern int strncmp(const char *s1, const char *s2, size_t n);
  63. extern size_t strxfrm(char *dest, const char *src, size_t n);
  64. /* Search functions: */
  65. extern void *memchr (const void *s, int c, size_t n);
  66. #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
  67. extern char *strchr (const char *s, char c); /* c should be int according to standard. */
  68. #else
  69. extern char *strchr (const char *s, int c);
  70. #endif
  71. extern size_t strcspn(const char *s, const char *reject);
  72. extern char *strpbrk(const char *s, const char *accept);
  73. #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
  74. extern char *strrchr(const char *s, char c); /* c should be int according to standard. */
  75. #else
  76. extern char *strrchr(const char *s, int c);
  77. #endif
  78. extern size_t strspn (const char *s, const char *accept);
  79. extern char *strstr (const char *haystack, const char *needle);
  80. extern char *strtok (char * /* restrict*/ str, const char * /*restrict*/ delim);
  81. /* Miscanelleous functions: */
  82. #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
  83. extern void *memset (void *s, unsigned char c, size_t n); /* c should be int according to standard. */
  84. #else
  85. extern void *memset (void *s, int c, size_t n);
  86. #endif
  87. /* extern char *strerror(int errnum); */
  88. extern size_t strlen (const char *s);
  89. #ifdef __SDCC_ds390
  90. extern void __xdata * memcpyx(void __xdata *, void __xdata *, int) __naked;
  91. #endif
  92. #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka)
  93. #define memcpy(dst, src, n) __builtin_memcpy(dst, src, n)
  94. #define strcpy(dst, src) __builtin_strcpy(dst, src)
  95. #define strncpy(dst, src, n) __builtin_strncpy(dst, src, n)
  96. #define strchr(s, c) __builtin_strchr(s, c)
  97. #define memset(dst, c, n) __builtin_memset(dst, c, n)
  98. #endif
  99. #endif