Imported Upstream version 2.5.2p1
[debian/amanda] / gnulib / string_.h
1 /* A GNU-like <string.h>.
2
3    Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc.
4
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.
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 General Public License for more details.
14
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.  */
18
19 #ifndef _GL_STRING_H
20 #define _GL_STRING_H
21
22 #include @ABSOLUTE_STRING_H@
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
29 #if ! @HAVE_DECL_MEMMEM@
30 extern void *memmem (void const *__haystack, size_t __haystack_len,
31                      void const *__needle, size_t __needle_len);
32 #endif
33
34 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
35    last written byte.  */
36 #if ! @HAVE_MEMPCPY@
37 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
38                       size_t __n);
39 #endif
40
41 /* Search backwards through a block for a byte (specified as an int).  */
42 #if ! @HAVE_DECL_MEMRCHR@
43 extern void *memrchr (void const *, int, size_t);
44 #endif
45
46 /* Copy SRC to DST, returning the address of the terminating '\0' in DST.  */
47 #if ! @HAVE_STPCPY@
48 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
49 #endif
50
51 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
52    last non-NUL byte written into DST.  */
53 #if ! @HAVE_STPNCPY@
54 # define stpncpy gnu_stpncpy
55 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
56                       size_t __n);
57 #endif
58
59 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
60    greater than zero if S1 is lexicographically less than, equal to or greater
61    than S2.
62    Note: This function may, in multibyte locales, return 0 for strings of
63    different lengths!
64    No known system has a strcasecmp() function that works correctly in
65    multibyte locales.  Therefore use our version always, if the
66    strcase module is available.  */
67 #if @REPLACE_STRCASECMP@
68 # define strcasecmp rpl_strcasecmp
69 extern int strcasecmp (char const *__s1, char const *__s2);
70 #endif
71
72 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
73    returning less than, equal to or greater than zero if S1 is
74    lexicographically less than, equal to or greater than S2.
75    Note: This function cannot work correctly in multibyte locales.  */
76 #if ! @HAVE_DECL_STRNCASECMP@
77 extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
78 #endif
79
80 /* Find the first occurrence of C in S or the final NUL byte.  */
81 #if ! @HAVE_STRCHRNUL@
82 extern char *strchrnul (char const *__s, int __c_in);
83 #endif
84
85 /* Duplicate S, returning an identical malloc'd string.  */
86 #if ! @HAVE_DECL_STRDUP@ && ! defined strdup
87 extern char *strdup (char const *__s);
88 #endif
89
90 /* Return a newly allocated copy of at most N bytes of STRING.  */
91 #if ! @HAVE_STRNDUP@
92 # undef strndup
93 # define strndup rpl_strndup
94 # if ! @HAVE_DECL_STRNDUP@
95 extern char *strndup (char const *__string, size_t __n);
96 # endif
97 #endif
98
99 /* Find the length (number of bytes) of STRING, but scan at most
100    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
101    return MAXLEN.  */
102 #if ! @HAVE_DECL_STRNLEN@
103 extern size_t strnlen (char const *__string, size_t __maxlen);
104 #endif
105
106 /* Find the first occurrence in S of any character in ACCEPT.  */
107 #if ! @HAVE_STRPBRK@
108 extern char *strpbrk (char const *__s, char const *__accept);
109 #endif
110
111 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
112    If one is found, overwrite it with a NUL, and advance *STRINGP
113    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
114    If *STRINGP was already NULL, nothing happens.
115    Return the old value of *STRINGP.
116
117    This is a variant of strtok() that is multithread-safe and supports
118    empty fields.
119
120    Caveat: It modifies the original string.
121    Caveat: These functions cannot be used on constant strings.
122    Caveat: The identity of the delimiting character is lost.
123    Caveat: It doesn't work with multibyte strings unless all of the delimiter
124            characters are ASCII characters < 0x30.
125
126    See also strtok_r().  */
127 #if ! @HAVE_STRSEP@
128 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
129 #endif
130
131 /* Find the first occurrence of NEEDLE in HAYSTACK.
132    No known system has a strstr() function that works correctly in
133    multibyte locales.  Therefore use our version always, if the strstr
134    module is available.  */
135 #if @REPLACE_STRSTR@
136 # undef strstr
137 # define strstr rpl_strstr
138 extern char *strstr (char const *__haystack, char const *__needle);
139 #endif
140
141 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
142    comparison.
143    Note: This function may, in multibyte locales, return success even if
144    strlen (haystack) < strlen (needle) !  */
145 #if @REPLACE_STRCASESTR@
146 # undef strcasestr
147 # define strcasestr rpl_strcasestr
148 extern char *strcasestr (const char *haystack, const char *needle);
149 #endif
150
151 /* Parse S into tokens separated by characters in DELIM.
152    If S is NULL, the saved pointer in SAVE_PTR is used as
153    the next starting point.  For example:
154         char s[] = "-abc-=-def";
155         char *sp;
156         x = strtok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
157         x = strtok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
158         x = strtok_r(NULL, "=", &sp);   // x = NULL
159                 // s = "abc\0-def\0"
160
161    This is a variant of strtok() that is multithread-safe.
162
163    For the POSIX documentation for this function, see:
164    http://www.opengroup.org/susv3xsh/strtok.html
165
166    Caveat: It modifies the original string.
167    Caveat: These functions cannot be used on constant strings.
168    Caveat: The identity of the delimiting character is lost.
169    Caveat: It doesn't work with multibyte strings unless all of the delimiter
170            characters are ASCII characters < 0x30.
171
172    See also strsep().  */
173 #if ! @HAVE_DECL_STRTOK_R@
174 extern char *strtok_r (char *restrict __s, char const *restrict __sep,
175                        char **restrict __lasts);
176 #endif
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif