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