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