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