Enforce the use of gnulib modules for unportable <string.h> functions.
[pspp] / lib / string_.h
1 /* A GNU-like <string.h>.
2
3    Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #ifndef _GL_STRING_H
20 #define _GL_STRING_H
21
22 #include @ABSOLUTE_STRING_H@
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
29 #if @GNULIB_MEMMEM@
30 # if ! @HAVE_DECL_MEMMEM@
31 extern void *memmem (void const *__haystack, size_t __haystack_len,
32                      void const *__needle, size_t __needle_len);
33 # endif
34 #else
35 # define memmem memmem_is_unportable__use_gnulib_module_memmem_for_portability
36 #endif
37
38 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
39    last written byte.  */
40 #if @GNULIB_MEMPCPY@
41 # if ! @HAVE_MEMPCPY@
42 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
43                       size_t __n);
44 # endif
45 #else
46 # define mempcpy mempcpy_is_unportable__use_gnulib_module_mempcpy_for_portability
47 #endif
48
49 /* Search backwards through a block for a byte (specified as an int).  */
50 #if @GNULIB_MEMRCHR@
51 # if ! @HAVE_DECL_MEMRCHR@
52 extern void *memrchr (void const *, int, size_t);
53 # endif
54 #else
55 # define memrchr memrchr_is_unportable__use_gnulib_module_memrchr_for_portability
56 #endif
57
58 /* Copy SRC to DST, returning the address of the terminating '\0' in DST.  */
59 #if @GNULIB_STPCPY@
60 # if ! @HAVE_STPCPY@
61 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
62 # endif
63 #else
64 # define stpcpy stpcpy_is_unportable__use_gnulib_module_stpcpy_for_portability
65 #endif
66
67 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
68    last non-NUL byte written into DST.  */
69 #if @GNULIB_STPNCPY@
70 # if ! @HAVE_STPNCPY@
71 #  define stpncpy gnu_stpncpy
72 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
73                       size_t __n);
74 # endif
75 #else
76 # define stpncpy stpncpy_is_unportable__use_gnulib_module_stpncpy_for_portability
77 #endif
78
79 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
80    greater than zero if S1 is lexicographically less than, equal to or greater
81    than S2.
82    Note: This function may, in multibyte locales, return 0 for strings of
83    different lengths!
84    No known system has a strcasecmp() function that works correctly in
85    multibyte locales.  Therefore use our version always, if the
86    strcase module is available.  */
87 #if @GNULIB_STRCASE@
88 # if @REPLACE_STRCASECMP@
89 #  define strcasecmp rpl_strcasecmp
90 extern int strcasecmp (char const *__s1, char const *__s2);
91 # endif
92 #else
93 # define strcasecmp strcasecmp_is_unportable__use_gnulib_module_strcase_for_portability
94 #endif
95
96 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
97    returning less than, equal to or greater than zero if S1 is
98    lexicographically less than, equal to or greater than S2.
99    Note: This function cannot work correctly in multibyte locales.  */
100 #if @GNULIB_STRCASE@
101 # if ! @HAVE_DECL_STRNCASECMP@
102 extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
103 # endif
104 #else
105 # define strncasecmp strncasecmp_is_unportable__use_gnulib_module_strcase_for_portability
106 #endif
107
108 /* Find the first occurrence of C in S or the final NUL byte.  */
109 #if @GNULIB_STRCHRNUL@
110 # if ! @HAVE_STRCHRNUL@
111 extern char *strchrnul (char const *__s, int __c_in);
112 # endif
113 #else
114 # define strchrnul strchrnul_is_unportable__use_gnulib_module_strchrnul_for_portability
115 #endif
116
117 /* Duplicate S, returning an identical malloc'd string.  */
118 #if @GNULIB_STRDUP@
119 # if ! @HAVE_DECL_STRDUP@ && ! defined strdup
120 extern char *strdup (char const *__s);
121 # endif
122 #else
123 # define strdup strdup_is_unportable__use_gnulib_module_strdup_for_portability
124 #endif
125
126 /* Return a newly allocated copy of at most N bytes of STRING.  */
127 #if @GNULIB_STRNDUP@
128 # if ! @HAVE_STRNDUP@
129 #  undef strndup
130 #  define strndup rpl_strndup
131 #  if ! @HAVE_DECL_STRNDUP@
132 extern char *strndup (char const *__string, size_t __n);
133 #  endif
134 # endif
135 #else
136 # define strndup strndup_is_unportable__use_gnulib_module_strndup_for_portability
137 #endif
138
139 /* Find the length (number of bytes) of STRING, but scan at most
140    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
141    return MAXLEN.  */
142 #if @GNULIB_STRNLEN@
143 # if ! @HAVE_DECL_STRNLEN@
144 extern size_t strnlen (char const *__string, size_t __maxlen);
145 # endif
146 #else
147 # define strnlen strnlen_is_unportable__use_gnulib_module_strnlen_for_portability
148 #endif
149
150 /* Find the first occurrence in S of any character in ACCEPT.  */
151 #if @GNULIB_STRPBRK@
152 # if ! @HAVE_STRPBRK@
153 extern char *strpbrk (char const *__s, char const *__accept);
154 # endif
155 #else
156 # define strpbrk strpbrk_is_unportable__use_gnulib_module_strpbrk_for_portability
157 #endif
158
159 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
160    If one is found, overwrite it with a NUL, and advance *STRINGP
161    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
162    If *STRINGP was already NULL, nothing happens.
163    Return the old value of *STRINGP.
164
165    This is a variant of strtok() that is multithread-safe and supports
166    empty fields.
167
168    Caveat: It modifies the original string.
169    Caveat: These functions cannot be used on constant strings.
170    Caveat: The identity of the delimiting character is lost.
171    Caveat: It doesn't work with multibyte strings unless all of the delimiter
172            characters are ASCII characters < 0x30.
173
174    See also strtok_r().  */
175 #if @GNULIB_STRSEP@
176 # if ! @HAVE_STRSEP@
177 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
178 # endif
179 #else
180 # define strsep strsep_is_unportable__use_gnulib_module_strsep_for_portability
181 #endif
182
183 /* Find the first occurrence of NEEDLE in HAYSTACK.
184    No known system has a strstr() function that works correctly in
185    multibyte locales.  Therefore use our version always, if the strstr
186    module is available.  */
187 #if @GNULIB_STRSTR@
188 # if @REPLACE_STRSTR@
189 #  undef strstr
190 #  define strstr rpl_strstr
191 extern char *strstr (char const *__haystack, char const *__needle);
192 # endif
193 #else
194 # define strstr strstr_is_unportable__use_gnulib_module_strstr_for_portability
195 #endif
196
197 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
198    comparison.
199    Note: This function may, in multibyte locales, return success even if
200    strlen (haystack) < strlen (needle) !  */
201 #if @GNULIB_STRCASESTR@
202 # if @REPLACE_STRCASESTR@
203 #  undef strcasestr
204 #  define strcasestr rpl_strcasestr
205 extern char *strcasestr (const char *haystack, const char *needle);
206 # endif
207 #else
208 # define strcasestr strcasestr_is_unportable__use_gnulib_module_strcasestr_for_portability
209 #endif
210
211 /* Parse S into tokens separated by characters in DELIM.
212    If S is NULL, the saved pointer in SAVE_PTR is used as
213    the next starting point.  For example:
214         char s[] = "-abc-=-def";
215         char *sp;
216         x = strtok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
217         x = strtok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
218         x = strtok_r(NULL, "=", &sp);   // x = NULL
219                 // s = "abc\0-def\0"
220
221    This is a variant of strtok() that is multithread-safe.
222
223    For the POSIX documentation for this function, see:
224    http://www.opengroup.org/susv3xsh/strtok.html
225
226    Caveat: It modifies the original string.
227    Caveat: These functions cannot be used on constant strings.
228    Caveat: The identity of the delimiting character is lost.
229    Caveat: It doesn't work with multibyte strings unless all of the delimiter
230            characters are ASCII characters < 0x30.
231
232    See also strsep().  */
233 #if @GNULIB_STRTOK_R@
234 # if ! @HAVE_DECL_STRTOK_R@
235 extern char *strtok_r (char *restrict __s, char const *restrict __sep,
236                        char **restrict __lasts);
237 # endif
238 #else
239 # define strtok_r strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability
240 #endif
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246 #endif