Commit | Line | Data |
---|---|---|
24d56127 LC |
1 | /* A GNU-like <string.h>. |
2 | ||
ffca4c22 | 3 | Copyright (C) 1995-1996, 2001-2009 Free Software Foundation, Inc. |
24d56127 LC |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser 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 Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser 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 | ||
21 | #if __GNUC__ >= 3 | |
22 | @PRAGMA_SYSTEM_HEADER@ | |
23 | #endif | |
24 | ||
25 | /* The include_next requires a split double-inclusion guard. */ | |
26 | #@INCLUDE_NEXT@ @NEXT_STRING_H@ | |
27 | ||
28 | #ifndef _GL_STRING_H | |
29 | #define _GL_STRING_H | |
30 | ||
31 | ||
32 | #ifndef __attribute__ | |
33 | /* This feature is available in gcc versions 2.5 and later. */ | |
34 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) | |
35 | # define __attribute__(Spec) /* empty */ | |
36 | # endif | |
37 | /* The attribute __pure__ was added in gcc 2.96. */ | |
38 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) | |
39 | # define __pure__ /* empty */ | |
40 | # endif | |
41 | #endif | |
42 | ||
43 | ||
44 | /* The definition of GL_LINK_WARNING is copied here. */ | |
45 | ||
46 | ||
47 | #ifdef __cplusplus | |
48 | extern "C" { | |
49 | #endif | |
50 | ||
51 | ||
ffca4c22 AW |
52 | /* Return the first instance of C within N bytes of S, or NULL. */ |
53 | #if @GNULIB_MEMCHR@ | |
54 | # if @REPLACE_MEMCHR@ | |
55 | # define memchr rpl_memchr | |
56 | extern void *memchr (void const *__s, int __c, size_t __n) | |
57 | __attribute__ ((__pure__)); | |
58 | # endif | |
59 | #elif defined GNULIB_POSIXCHECK | |
60 | # undef memchr | |
61 | # define memchr(s,c,n) \ | |
62 | (GL_LINK_WARNING ("memchr has platform-specific bugs - " \ | |
63 | "use gnulib module memchr for portability" ), \ | |
64 | memchr (s, c, n)) | |
65 | #endif | |
66 | ||
24d56127 LC |
67 | /* Return the first occurrence of NEEDLE in HAYSTACK. */ |
68 | #if @GNULIB_MEMMEM@ | |
69 | # if @REPLACE_MEMMEM@ | |
70 | # define memmem rpl_memmem | |
71 | # endif | |
72 | # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ | |
73 | extern void *memmem (void const *__haystack, size_t __haystack_len, | |
74 | void const *__needle, size_t __needle_len) | |
75 | __attribute__ ((__pure__)); | |
76 | # endif | |
77 | #elif defined GNULIB_POSIXCHECK | |
78 | # undef memmem | |
79 | # define memmem(a,al,b,bl) \ | |
80 | (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \ | |
81 | "use gnulib module memmem-simple for portability, " \ | |
82 | "and module memmem for speed" ), \ | |
83 | memmem (a, al, b, bl)) | |
84 | #endif | |
85 | ||
86 | /* Copy N bytes of SRC to DEST, return pointer to bytes after the | |
87 | last written byte. */ | |
88 | #if @GNULIB_MEMPCPY@ | |
89 | # if ! @HAVE_MEMPCPY@ | |
90 | extern void *mempcpy (void *restrict __dest, void const *restrict __src, | |
91 | size_t __n); | |
92 | # endif | |
93 | #elif defined GNULIB_POSIXCHECK | |
94 | # undef mempcpy | |
95 | # define mempcpy(a,b,n) \ | |
96 | (GL_LINK_WARNING ("mempcpy is unportable - " \ | |
97 | "use gnulib module mempcpy for portability"), \ | |
98 | mempcpy (a, b, n)) | |
99 | #endif | |
100 | ||
101 | /* Search backwards through a block for a byte (specified as an int). */ | |
102 | #if @GNULIB_MEMRCHR@ | |
103 | # if ! @HAVE_DECL_MEMRCHR@ | |
104 | extern void *memrchr (void const *, int, size_t) | |
105 | __attribute__ ((__pure__)); | |
106 | # endif | |
107 | #elif defined GNULIB_POSIXCHECK | |
108 | # undef memrchr | |
109 | # define memrchr(a,b,c) \ | |
110 | (GL_LINK_WARNING ("memrchr is unportable - " \ | |
111 | "use gnulib module memrchr for portability"), \ | |
112 | memrchr (a, b, c)) | |
113 | #endif | |
114 | ||
115 | /* Find the first occurrence of C in S. More efficient than | |
116 | memchr(S,C,N), at the expense of undefined behavior if C does not | |
117 | occur within N bytes. */ | |
118 | #if @GNULIB_RAWMEMCHR@ | |
119 | # if ! @HAVE_RAWMEMCHR@ | |
120 | extern void *rawmemchr (void const *__s, int __c_in) | |
121 | __attribute__ ((__pure__)); | |
122 | # endif | |
123 | #elif defined GNULIB_POSIXCHECK | |
124 | # undef rawmemchr | |
125 | # define rawmemchr(a,b) \ | |
126 | (GL_LINK_WARNING ("rawmemchr is unportable - " \ | |
127 | "use gnulib module rawmemchr for portability"), \ | |
128 | rawmemchr (a, b)) | |
129 | #endif | |
130 | ||
131 | /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ | |
132 | #if @GNULIB_STPCPY@ | |
133 | # if ! @HAVE_STPCPY@ | |
134 | extern char *stpcpy (char *restrict __dst, char const *restrict __src); | |
135 | # endif | |
136 | #elif defined GNULIB_POSIXCHECK | |
137 | # undef stpcpy | |
138 | # define stpcpy(a,b) \ | |
139 | (GL_LINK_WARNING ("stpcpy is unportable - " \ | |
140 | "use gnulib module stpcpy for portability"), \ | |
141 | stpcpy (a, b)) | |
142 | #endif | |
143 | ||
144 | /* Copy no more than N bytes of SRC to DST, returning a pointer past the | |
145 | last non-NUL byte written into DST. */ | |
146 | #if @GNULIB_STPNCPY@ | |
147 | # if ! @HAVE_STPNCPY@ | |
148 | # define stpncpy gnu_stpncpy | |
149 | extern char *stpncpy (char *restrict __dst, char const *restrict __src, | |
150 | size_t __n); | |
151 | # endif | |
152 | #elif defined GNULIB_POSIXCHECK | |
153 | # undef stpncpy | |
154 | # define stpncpy(a,b,n) \ | |
155 | (GL_LINK_WARNING ("stpncpy is unportable - " \ | |
156 | "use gnulib module stpncpy for portability"), \ | |
157 | stpncpy (a, b, n)) | |
158 | #endif | |
159 | ||
160 | #if defined GNULIB_POSIXCHECK | |
161 | /* strchr() does not work with multibyte strings if the locale encoding is | |
162 | GB18030 and the character to be searched is a digit. */ | |
163 | # undef strchr | |
164 | # define strchr(s,c) \ | |
165 | (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ | |
166 | "in some multibyte locales - " \ | |
167 | "use mbschr if you care about internationalization"), \ | |
168 | strchr (s, c)) | |
169 | #endif | |
170 | ||
171 | /* Find the first occurrence of C in S or the final NUL byte. */ | |
172 | #if @GNULIB_STRCHRNUL@ | |
173 | # if ! @HAVE_STRCHRNUL@ | |
174 | extern char *strchrnul (char const *__s, int __c_in) | |
175 | __attribute__ ((__pure__)); | |
176 | # endif | |
177 | #elif defined GNULIB_POSIXCHECK | |
178 | # undef strchrnul | |
179 | # define strchrnul(a,b) \ | |
180 | (GL_LINK_WARNING ("strchrnul is unportable - " \ | |
181 | "use gnulib module strchrnul for portability"), \ | |
182 | strchrnul (a, b)) | |
183 | #endif | |
184 | ||
185 | /* Duplicate S, returning an identical malloc'd string. */ | |
186 | #if @GNULIB_STRDUP@ | |
187 | # if @REPLACE_STRDUP@ | |
188 | # undef strdup | |
189 | # define strdup rpl_strdup | |
190 | # endif | |
191 | # if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@ | |
192 | extern char *strdup (char const *__s); | |
193 | # endif | |
194 | #elif defined GNULIB_POSIXCHECK | |
195 | # undef strdup | |
196 | # define strdup(a) \ | |
197 | (GL_LINK_WARNING ("strdup is unportable - " \ | |
198 | "use gnulib module strdup for portability"), \ | |
199 | strdup (a)) | |
200 | #endif | |
201 | ||
202 | /* Return a newly allocated copy of at most N bytes of STRING. */ | |
203 | #if @GNULIB_STRNDUP@ | |
204 | # if ! @HAVE_STRNDUP@ | |
205 | # undef strndup | |
206 | # define strndup rpl_strndup | |
207 | # endif | |
208 | # if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ | |
209 | extern char *strndup (char const *__string, size_t __n); | |
210 | # endif | |
211 | #elif defined GNULIB_POSIXCHECK | |
212 | # undef strndup | |
213 | # define strndup(a,n) \ | |
214 | (GL_LINK_WARNING ("strndup is unportable - " \ | |
215 | "use gnulib module strndup for portability"), \ | |
216 | strndup (a, n)) | |
217 | #endif | |
218 | ||
219 | /* Find the length (number of bytes) of STRING, but scan at most | |
220 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, | |
221 | return MAXLEN. */ | |
222 | #if @GNULIB_STRNLEN@ | |
223 | # if ! @HAVE_DECL_STRNLEN@ | |
224 | extern size_t strnlen (char const *__string, size_t __maxlen) | |
225 | __attribute__ ((__pure__)); | |
226 | # endif | |
227 | #elif defined GNULIB_POSIXCHECK | |
228 | # undef strnlen | |
229 | # define strnlen(a,n) \ | |
230 | (GL_LINK_WARNING ("strnlen is unportable - " \ | |
231 | "use gnulib module strnlen for portability"), \ | |
232 | strnlen (a, n)) | |
233 | #endif | |
234 | ||
235 | #if defined GNULIB_POSIXCHECK | |
236 | /* strcspn() assumes the second argument is a list of single-byte characters. | |
237 | Even in this simple case, it does not work with multibyte strings if the | |
238 | locale encoding is GB18030 and one of the characters to be searched is a | |
239 | digit. */ | |
240 | # undef strcspn | |
241 | # define strcspn(s,a) \ | |
242 | (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ | |
243 | "in multibyte locales - " \ | |
244 | "use mbscspn if you care about internationalization"), \ | |
245 | strcspn (s, a)) | |
246 | #endif | |
247 | ||
248 | /* Find the first occurrence in S of any character in ACCEPT. */ | |
249 | #if @GNULIB_STRPBRK@ | |
250 | # if ! @HAVE_STRPBRK@ | |
251 | extern char *strpbrk (char const *__s, char const *__accept) | |
252 | __attribute__ ((__pure__)); | |
253 | # endif | |
254 | # if defined GNULIB_POSIXCHECK | |
255 | /* strpbrk() assumes the second argument is a list of single-byte characters. | |
256 | Even in this simple case, it does not work with multibyte strings if the | |
257 | locale encoding is GB18030 and one of the characters to be searched is a | |
258 | digit. */ | |
259 | # undef strpbrk | |
260 | # define strpbrk(s,a) \ | |
261 | (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ | |
262 | "in multibyte locales - " \ | |
263 | "use mbspbrk if you care about internationalization"), \ | |
264 | strpbrk (s, a)) | |
265 | # endif | |
266 | #elif defined GNULIB_POSIXCHECK | |
267 | # undef strpbrk | |
268 | # define strpbrk(s,a) \ | |
269 | (GL_LINK_WARNING ("strpbrk is unportable - " \ | |
270 | "use gnulib module strpbrk for portability"), \ | |
271 | strpbrk (s, a)) | |
272 | #endif | |
273 | ||
274 | #if defined GNULIB_POSIXCHECK | |
275 | /* strspn() assumes the second argument is a list of single-byte characters. | |
276 | Even in this simple case, it cannot work with multibyte strings. */ | |
277 | # undef strspn | |
278 | # define strspn(s,a) \ | |
279 | (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ | |
280 | "in multibyte locales - " \ | |
281 | "use mbsspn if you care about internationalization"), \ | |
282 | strspn (s, a)) | |
283 | #endif | |
284 | ||
285 | #if defined GNULIB_POSIXCHECK | |
286 | /* strrchr() does not work with multibyte strings if the locale encoding is | |
287 | GB18030 and the character to be searched is a digit. */ | |
288 | # undef strrchr | |
289 | # define strrchr(s,c) \ | |
290 | (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ | |
291 | "in some multibyte locales - " \ | |
292 | "use mbsrchr if you care about internationalization"), \ | |
293 | strrchr (s, c)) | |
294 | #endif | |
295 | ||
296 | /* Search the next delimiter (char listed in DELIM) starting at *STRINGP. | |
297 | If one is found, overwrite it with a NUL, and advance *STRINGP | |
298 | to point to the next char after it. Otherwise, set *STRINGP to NULL. | |
299 | If *STRINGP was already NULL, nothing happens. | |
300 | Return the old value of *STRINGP. | |
301 | ||
302 | This is a variant of strtok() that is multithread-safe and supports | |
303 | empty fields. | |
304 | ||
305 | Caveat: It modifies the original string. | |
306 | Caveat: These functions cannot be used on constant strings. | |
307 | Caveat: The identity of the delimiting character is lost. | |
308 | Caveat: It doesn't work with multibyte strings unless all of the delimiter | |
309 | characters are ASCII characters < 0x30. | |
310 | ||
311 | See also strtok_r(). */ | |
312 | #if @GNULIB_STRSEP@ | |
313 | # if ! @HAVE_STRSEP@ | |
314 | extern char *strsep (char **restrict __stringp, char const *restrict __delim); | |
315 | # endif | |
316 | # if defined GNULIB_POSIXCHECK | |
317 | # undef strsep | |
318 | # define strsep(s,d) \ | |
319 | (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ | |
320 | "in multibyte locales - " \ | |
321 | "use mbssep if you care about internationalization"), \ | |
322 | strsep (s, d)) | |
323 | # endif | |
324 | #elif defined GNULIB_POSIXCHECK | |
325 | # undef strsep | |
326 | # define strsep(s,d) \ | |
327 | (GL_LINK_WARNING ("strsep is unportable - " \ | |
328 | "use gnulib module strsep for portability"), \ | |
329 | strsep (s, d)) | |
330 | #endif | |
331 | ||
332 | #if @GNULIB_STRSTR@ | |
333 | # if @REPLACE_STRSTR@ | |
334 | # define strstr rpl_strstr | |
335 | char *strstr (const char *haystack, const char *needle) | |
336 | __attribute__ ((__pure__)); | |
337 | # endif | |
338 | #elif defined GNULIB_POSIXCHECK | |
339 | /* strstr() does not work with multibyte strings if the locale encoding is | |
340 | different from UTF-8: | |
341 | POSIX says that it operates on "strings", and "string" in POSIX is defined | |
342 | as a sequence of bytes, not of characters. */ | |
343 | # undef strstr | |
344 | # define strstr(a,b) \ | |
345 | (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \ | |
346 | "work correctly on character strings in most " \ | |
347 | "multibyte locales - " \ | |
348 | "use mbsstr if you care about internationalization, " \ | |
349 | "or use strstr if you care about speed"), \ | |
350 | strstr (a, b)) | |
351 | #endif | |
352 | ||
353 | /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive | |
354 | comparison. */ | |
355 | #if @GNULIB_STRCASESTR@ | |
356 | # if @REPLACE_STRCASESTR@ | |
357 | # define strcasestr rpl_strcasestr | |
358 | # endif | |
359 | # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@ | |
360 | extern char *strcasestr (const char *haystack, const char *needle) | |
361 | __attribute__ ((__pure__)); | |
362 | # endif | |
363 | #elif defined GNULIB_POSIXCHECK | |
364 | /* strcasestr() does not work with multibyte strings: | |
365 | It is a glibc extension, and glibc implements it only for unibyte | |
366 | locales. */ | |
367 | # undef strcasestr | |
368 | # define strcasestr(a,b) \ | |
369 | (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ | |
370 | "in multibyte locales - " \ | |
371 | "use mbscasestr if you care about " \ | |
372 | "internationalization, or use c-strcasestr if you want " \ | |
373 | "a locale independent function"), \ | |
374 | strcasestr (a, b)) | |
375 | #endif | |
376 | ||
377 | /* Parse S into tokens separated by characters in DELIM. | |
378 | If S is NULL, the saved pointer in SAVE_PTR is used as | |
379 | the next starting point. For example: | |
380 | char s[] = "-abc-=-def"; | |
381 | char *sp; | |
382 | x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" | |
383 | x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL | |
384 | x = strtok_r(NULL, "=", &sp); // x = NULL | |
385 | // s = "abc\0-def\0" | |
386 | ||
387 | This is a variant of strtok() that is multithread-safe. | |
388 | ||
389 | For the POSIX documentation for this function, see: | |
390 | http://www.opengroup.org/susv3xsh/strtok.html | |
391 | ||
392 | Caveat: It modifies the original string. | |
393 | Caveat: These functions cannot be used on constant strings. | |
394 | Caveat: The identity of the delimiting character is lost. | |
395 | Caveat: It doesn't work with multibyte strings unless all of the delimiter | |
396 | characters are ASCII characters < 0x30. | |
397 | ||
398 | See also strsep(). */ | |
399 | #if @GNULIB_STRTOK_R@ | |
400 | # if ! @HAVE_DECL_STRTOK_R@ | |
401 | extern char *strtok_r (char *restrict s, char const *restrict delim, | |
402 | char **restrict save_ptr); | |
403 | # endif | |
404 | # if defined GNULIB_POSIXCHECK | |
405 | # undef strtok_r | |
406 | # define strtok_r(s,d,p) \ | |
407 | (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ | |
408 | "in multibyte locales - " \ | |
409 | "use mbstok_r if you care about internationalization"), \ | |
410 | strtok_r (s, d, p)) | |
411 | # endif | |
412 | #elif defined GNULIB_POSIXCHECK | |
413 | # undef strtok_r | |
414 | # define strtok_r(s,d,p) \ | |
415 | (GL_LINK_WARNING ("strtok_r is unportable - " \ | |
416 | "use gnulib module strtok_r for portability"), \ | |
417 | strtok_r (s, d, p)) | |
418 | #endif | |
419 | ||
420 | ||
421 | /* The following functions are not specified by POSIX. They are gnulib | |
422 | extensions. */ | |
423 | ||
424 | #if @GNULIB_MBSLEN@ | |
425 | /* Return the number of multibyte characters in the character string STRING. | |
426 | This considers multibyte characters, unlike strlen, which counts bytes. */ | |
427 | extern size_t mbslen (const char *string); | |
428 | #endif | |
429 | ||
430 | #if @GNULIB_MBSNLEN@ | |
431 | /* Return the number of multibyte characters in the character string starting | |
432 | at STRING and ending at STRING + LEN. */ | |
433 | extern size_t mbsnlen (const char *string, size_t len); | |
434 | #endif | |
435 | ||
436 | #if @GNULIB_MBSCHR@ | |
437 | /* Locate the first single-byte character C in the character string STRING, | |
438 | and return a pointer to it. Return NULL if C is not found in STRING. | |
439 | Unlike strchr(), this function works correctly in multibyte locales with | |
440 | encodings such as GB18030. */ | |
441 | # define mbschr rpl_mbschr /* avoid collision with HP-UX function */ | |
442 | extern char * mbschr (const char *string, int c); | |
443 | #endif | |
444 | ||
445 | #if @GNULIB_MBSRCHR@ | |
446 | /* Locate the last single-byte character C in the character string STRING, | |
447 | and return a pointer to it. Return NULL if C is not found in STRING. | |
448 | Unlike strrchr(), this function works correctly in multibyte locales with | |
449 | encodings such as GB18030. */ | |
450 | # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ | |
451 | extern char * mbsrchr (const char *string, int c); | |
452 | #endif | |
453 | ||
454 | #if @GNULIB_MBSSTR@ | |
455 | /* Find the first occurrence of the character string NEEDLE in the character | |
456 | string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. | |
457 | Unlike strstr(), this function works correctly in multibyte locales with | |
458 | encodings different from UTF-8. */ | |
459 | extern char * mbsstr (const char *haystack, const char *needle); | |
460 | #endif | |
461 | ||
462 | #if @GNULIB_MBSCASECMP@ | |
463 | /* Compare the character strings S1 and S2, ignoring case, returning less than, | |
464 | equal to or greater than zero if S1 is lexicographically less than, equal to | |
465 | or greater than S2. | |
466 | Note: This function may, in multibyte locales, return 0 for strings of | |
467 | different lengths! | |
468 | Unlike strcasecmp(), this function works correctly in multibyte locales. */ | |
469 | extern int mbscasecmp (const char *s1, const char *s2); | |
470 | #endif | |
471 | ||
472 | #if @GNULIB_MBSNCASECMP@ | |
473 | /* Compare the initial segment of the character string S1 consisting of at most | |
474 | N characters with the initial segment of the character string S2 consisting | |
475 | of at most N characters, ignoring case, returning less than, equal to or | |
476 | greater than zero if the initial segment of S1 is lexicographically less | |
477 | than, equal to or greater than the initial segment of S2. | |
478 | Note: This function may, in multibyte locales, return 0 for initial segments | |
479 | of different lengths! | |
480 | Unlike strncasecmp(), this function works correctly in multibyte locales. | |
481 | But beware that N is not a byte count but a character count! */ | |
482 | extern int mbsncasecmp (const char *s1, const char *s2, size_t n); | |
483 | #endif | |
484 | ||
485 | #if @GNULIB_MBSPCASECMP@ | |
486 | /* Compare the initial segment of the character string STRING consisting of | |
487 | at most mbslen (PREFIX) characters with the character string PREFIX, | |
488 | ignoring case, returning less than, equal to or greater than zero if this | |
489 | initial segment is lexicographically less than, equal to or greater than | |
490 | PREFIX. | |
491 | Note: This function may, in multibyte locales, return 0 if STRING is of | |
492 | smaller length than PREFIX! | |
493 | Unlike strncasecmp(), this function works correctly in multibyte | |
494 | locales. */ | |
495 | extern char * mbspcasecmp (const char *string, const char *prefix); | |
496 | #endif | |
497 | ||
498 | #if @GNULIB_MBSCASESTR@ | |
499 | /* Find the first occurrence of the character string NEEDLE in the character | |
500 | string HAYSTACK, using case-insensitive comparison. | |
501 | Note: This function may, in multibyte locales, return success even if | |
502 | strlen (haystack) < strlen (needle) ! | |
503 | Unlike strcasestr(), this function works correctly in multibyte locales. */ | |
504 | extern char * mbscasestr (const char *haystack, const char *needle); | |
505 | #endif | |
506 | ||
507 | #if @GNULIB_MBSCSPN@ | |
508 | /* Find the first occurrence in the character string STRING of any character | |
509 | in the character string ACCEPT. Return the number of bytes from the | |
510 | beginning of the string to this occurrence, or to the end of the string | |
511 | if none exists. | |
512 | Unlike strcspn(), this function works correctly in multibyte locales. */ | |
513 | extern size_t mbscspn (const char *string, const char *accept); | |
514 | #endif | |
515 | ||
516 | #if @GNULIB_MBSPBRK@ | |
517 | /* Find the first occurrence in the character string STRING of any character | |
518 | in the character string ACCEPT. Return the pointer to it, or NULL if none | |
519 | exists. | |
520 | Unlike strpbrk(), this function works correctly in multibyte locales. */ | |
521 | # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ | |
522 | extern char * mbspbrk (const char *string, const char *accept); | |
523 | #endif | |
524 | ||
525 | #if @GNULIB_MBSSPN@ | |
526 | /* Find the first occurrence in the character string STRING of any character | |
527 | not in the character string REJECT. Return the number of bytes from the | |
528 | beginning of the string to this occurrence, or to the end of the string | |
529 | if none exists. | |
530 | Unlike strspn(), this function works correctly in multibyte locales. */ | |
531 | extern size_t mbsspn (const char *string, const char *reject); | |
532 | #endif | |
533 | ||
534 | #if @GNULIB_MBSSEP@ | |
535 | /* Search the next delimiter (multibyte character listed in the character | |
536 | string DELIM) starting at the character string *STRINGP. | |
537 | If one is found, overwrite it with a NUL, and advance *STRINGP to point | |
538 | to the next multibyte character after it. Otherwise, set *STRINGP to NULL. | |
539 | If *STRINGP was already NULL, nothing happens. | |
540 | Return the old value of *STRINGP. | |
541 | ||
542 | This is a variant of mbstok_r() that supports empty fields. | |
543 | ||
544 | Caveat: It modifies the original string. | |
545 | Caveat: These functions cannot be used on constant strings. | |
546 | Caveat: The identity of the delimiting character is lost. | |
547 | ||
548 | See also mbstok_r(). */ | |
549 | extern char * mbssep (char **stringp, const char *delim); | |
550 | #endif | |
551 | ||
552 | #if @GNULIB_MBSTOK_R@ | |
553 | /* Parse the character string STRING into tokens separated by characters in | |
554 | the character string DELIM. | |
555 | If STRING is NULL, the saved pointer in SAVE_PTR is used as | |
556 | the next starting point. For example: | |
557 | char s[] = "-abc-=-def"; | |
558 | char *sp; | |
559 | x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" | |
560 | x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL | |
561 | x = mbstok_r(NULL, "=", &sp); // x = NULL | |
562 | // s = "abc\0-def\0" | |
563 | ||
564 | Caveat: It modifies the original string. | |
565 | Caveat: These functions cannot be used on constant strings. | |
566 | Caveat: The identity of the delimiting character is lost. | |
567 | ||
568 | See also mbssep(). */ | |
569 | extern char * mbstok_r (char *string, const char *delim, char **save_ptr); | |
570 | #endif | |
571 | ||
572 | /* Map any int, typically from errno, into an error message. */ | |
573 | #if @GNULIB_STRERROR@ | |
574 | # if @REPLACE_STRERROR@ | |
575 | # undef strerror | |
576 | # define strerror rpl_strerror | |
577 | extern char *strerror (int); | |
578 | # endif | |
579 | #elif defined GNULIB_POSIXCHECK | |
580 | # undef strerror | |
581 | # define strerror(e) \ | |
582 | (GL_LINK_WARNING ("strerror is unportable - " \ | |
583 | "use gnulib module strerror to guarantee non-NULL result"), \ | |
584 | strerror (e)) | |
585 | #endif | |
586 | ||
587 | #if @GNULIB_STRSIGNAL@ | |
588 | # if @REPLACE_STRSIGNAL@ | |
589 | # define strsignal rpl_strsignal | |
590 | # endif | |
591 | # if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@ | |
592 | extern char *strsignal (int __sig); | |
593 | # endif | |
594 | #elif defined GNULIB_POSIXCHECK | |
595 | # undef strsignal | |
596 | # define strsignal(a) \ | |
597 | (GL_LINK_WARNING ("strsignal is unportable - " \ | |
598 | "use gnulib module strsignal for portability"), \ | |
599 | strsignal (a)) | |
600 | #endif | |
601 | ||
602 | #if @GNULIB_STRVERSCMP@ | |
603 | # if !@HAVE_STRVERSCMP@ | |
604 | extern int strverscmp (const char *, const char *); | |
605 | # endif | |
606 | #elif defined GNULIB_POSIXCHECK | |
607 | # undef strverscmp | |
608 | # define strverscmp(a, b) \ | |
609 | (GL_LINK_WARNING ("strverscmp is unportable - " \ | |
610 | "use gnulib module strverscmp for portability"), \ | |
611 | strverscmp (a, b)) | |
612 | #endif | |
613 | ||
614 | ||
615 | #ifdef __cplusplus | |
616 | } | |
617 | #endif | |
618 | ||
619 | #endif /* _GL_STRING_H */ | |
620 | #endif /* _GL_STRING_H */ |