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