1 /*-------------------------------------------------------------------------
2 string.h - ISO header for string library functions
4 Copyright (C) 1998, Sandeep Dutta
5 Copyright (C) 2009-2019, Philipp Klaus Krause pkk@spth.de
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 #ifndef __SDCC_STRING_H
31 #define __SDCC_STRING_H 1
34 # define NULL (void *)0
37 #ifndef __SIZE_T_DEFINED
38 # define __SIZE_T_DEFINED
39 typedef unsigned int size_t;
42 /* Bounds-checking interfaces from annex K of the C11 standard. */
43 #if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__
45 #ifndef __RSIZE_T_DEFINED
46 #define __RSIZE_T_DEFINED
47 typedef size_t rsize_t
;
50 #ifndef __ERRNO_T_DEFINED
51 #define __ERRNO_T_DEFINED
57 #if defined(__SDCC_mcs51) || defined(__SDCC_hc08) || defined(__SDCC_ds390) || defined(__SDCC_pic14) || defined(__SDCC_pic16) || defined(__SDCC_mos6502) || defined(__SDCC_mos65c02)
58 #define __SDCC_BROKEN_STRING_FUNCTIONS
61 /* The function prototypes are ordered as in the ISO C11 standard. */
63 /* Todo: fix the "restrict" stuff for C99 compliance. */
65 /* Copying functions: */
66 void *memccpy (void */
*restrict*/ dst
, const void */
*restict*/ src
, int c
, size_t n
);
67 extern void *memcpy (void * /*restrict */ dest
, const void * /*restrict*/ src
, size_t n
);
68 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka)
69 extern void *memmove (void *dest
, const void *src
, size_t n
) __preserves_regs(iyl
, iyh
);
71 extern void *memmove (void *dest
, const void *src
, size_t n
);
73 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined (__SDCC_ez80_z80) || defined (__SDCC_z80n) || defined(__SDCC_r800)
74 extern char *strcpy (char * /*restrict*/ dest
, const char * /*restrict*/ src
) __preserves_regs(iyl
, iyh
);
76 extern char *strcpy (char * /*restrict*/ dest
, const char * /*restrict*/ src
);
78 extern char *strncpy (char * /*restrict*/ dest
, const char * /*restrict*/ src
, size_t n
);
80 /* Concatenation functions: */
81 extern char *strcat (char * /*restrict*/ dest
, const char * /*restrict*/ src
);
82 extern char *strncat (char * /*restrict*/ dest
, const char * /*restrict*/ src
, size_t n
);
84 /* C2X Duplication functions */
85 extern char *strdup (const char *s
);
86 extern char *strndup (const char *s
, size_t n
);
88 /* Comparison functions: */
89 extern int memcmp (const void *s1
, const void *s2
, size_t n
);
90 extern int strcmp (const char *s1
, const char *s2
);
91 #define strcoll(s1, s2) strcmp(s1, s2)
92 /*int strcoll(const char *s1, const char *s2) {return strcmp(s1, s2);}*/
93 extern int strncmp (const char *s1
, const char *s2
, size_t n
);
94 extern size_t strxfrm (char *dest
, const char *src
, size_t n
);
96 /* Search functions: */
97 extern void *memchr (const void *s
, int c
, size_t n
);
98 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
99 extern char *strchr (const char *s
, char c
); /* c should be int according to standard. */
101 extern char *strchr (const char *s
, int c
);
103 extern size_t strcspn(const char *s
, const char *reject
);
104 extern char *strpbrk(const char *s
, const char *accept
);
105 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
106 extern char *strrchr(const char *s
, char c
); /* c should be int according to standard. */
108 extern char *strrchr(const char *s
, int c
);
110 extern size_t strspn (const char *s
, const char *accept
);
111 extern char *strstr (const char *haystack
, const char *needle
);
112 extern char *strtok (char * /* restrict*/ str
, const char * /*restrict*/ delim
);
114 /* Miscanelleous functions: */
115 #ifdef __SDCC_BROKEN_STRING_FUNCTIONS
116 extern void *memset (void *s
, unsigned char c
, size_t n
); /* c should be int according to standard. */
118 extern void *memset (void *s
, int c
, size_t n
);
121 extern void *memset_explicit (void *s
, int c
, size_t n
);
123 /* extern char *strerror(int errnum); */
124 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_tlcs90) || defined (__SDCC_ez80_z80) || defined (__SDCC_z80n) || defined(__SDCC_r800)
125 extern size_t strlen (const char *s
) __preserves_regs(iyl
, iyh
);
127 extern size_t strlen (const char *s
);
130 /* C2Y length function: */
131 extern size_t strnlen (const char *s
, size_t n
);
134 extern void __xdata
* memcpyx(void __xdata
*, void __xdata
*, int) __naked
;
137 #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r2ka) || defined(__SDCC_r3ka) || defined (__SDCC_ez80_z80) || defined (__SDCC_z80n) || defined(__SDCC_r800)
138 #define memcpy(dst, src, n) __builtin_memcpy(dst, src, n)
139 #define strcpy(dst, src) __builtin_strcpy(dst, src)
140 #define strncpy(dst, src, n) __builtin_strncpy(dst, src, n)
141 #define strchr(s, c) __builtin_strchr(s, c)
142 #define memset(dst, c, n) __builtin_memset(dst, c, n)
144 extern void *__memcpy (void * /*restrict */ dest
, const void * /*restrict*/ src
, size_t n
);
145 #define memcpy(dst, src, n) __memcpy(dst, src, n)