* doc/gnulib-tool.texi (Initial import): Update to match current
[pspp] / lib / string_.h
1 /* A GNU-like <string.h>.
2
3    Copyright (C) 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 void *
31 memmem (void const *__haystack, size_t __haystack_len,
32         void const *__needle, size_t __needle_len);
33 #endif
34
35 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
36    last written byte.  */
37 #if ! @HAVE_MEMPCPY@
38 void *mempcpy (void *restrict __dest, void const *restrict __src, 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 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 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 char *stpncpy (char *restrict __dst, char const *restrict __src, size_t __n);
56 #endif
57
58 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
59    greater than zero if S1 is lexicographically less than, equal to or greater
60    than S2.
61    Note: This function may, in multibyte locales, return 0 for strings of
62    different lengths!
63    No known system has a strcasecmp() function that works correctly in
64    multibyte locales.  Therefore use our version always, if the
65    strcase module is available.  */
66 #if @REPLACE_STRCASECMP@
67 # define strcasecmp rpl_strcasecmp
68 int strcasecmp (char const *__s1, char const *__s2);
69 #endif
70
71 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
72    returning less than, equal to or greater than zero if S1 is
73    lexicographically less than, equal to or greater than S2.
74    Note: This function cannot work correctly in multibyte locales.  */
75 #if ! @HAVE_DECL_STRNCASECMP@
76 int strncasecmp (char const *__s1, char const *__s2, size_t __n);
77 #endif
78
79 /* Find the first occurrence of C in S or the final NUL byte.  */
80 #if ! @HAVE_STRCHRNUL@
81 char *strchrnul (char const *__s, int __c_in);
82 #endif
83
84 /* Duplicate S, returning an identical malloc'd string.  */
85 #if ! @HAVE_DECL_STRDUP@ && ! defined strdup
86 char *strdup (char const *__s);
87 #endif
88
89 /* Return a newly allocated copy of at most N bytes of STRING.  */
90 #if ! @HAVE_STRNDUP@
91 # undef strndup
92 # define strndup rpl_strndup
93 # if ! @HAVE_DECL_STRNDUP@
94 char *strndup (char const *__string, size_t __n);
95 # endif
96 #endif
97
98 /* Find the length (number of bytes) of STRING, but scan at most
99    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
100    return MAXLEN.  */
101 #if ! @HAVE_DECL_STRNLEN@
102 size_t strnlen (char const *__string, size_t __maxlen);
103 #endif
104
105 /* Find the first occurrence in S of any character in ACCEPT.  */
106 #if ! @HAVE_STRPBRK@
107 char *strpbrk (char const *__s, char const *__accept);
108 #endif
109
110 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
111    If one is found, overwrite it with a NUL, and advance *STRINGP
112    to point to the next char after it.  Otherwise, set *STRINGP to NULL.
113    If *STRINGP was already NULL, nothing happens.
114    Return the old value of *STRINGP.
115
116    This is a variant of strtok() that is multithread-safe and supports
117    empty fields.
118
119    Caveat: It modifies the original string.
120    Caveat: These functions cannot be used on constant strings.
121    Caveat: The identity of the delimiting character is lost.
122    Caveat: It doesn't work with multibyte strings unless all of the delimiter
123            characters are ASCII characters < 0x30.
124
125    See also strtok_r().  */
126 #if ! @HAVE_STRSEP@
127 char *strsep (char **restrict __stringp, char const *restrict __delim);
128 #endif
129
130 /* Find the first occurrence of NEEDLE in HAYSTACK.
131    No known system has a strstr() function that works correctly in
132    multibyte locales.  Therefore use our version always, if the strstr
133    module is available.  */
134 #if @REPLACE_STRSTR@
135 # undef strstr
136 # define strstr rpl_strstr
137 char *strstr (char const *__haystack, char const *__needle);
138 #endif
139
140 /* Parse S into tokens separated by characters in DELIM.
141    If S is NULL, the saved pointer in SAVE_PTR is used as
142    the next starting point.  For example:
143         char s[] = "-abc-=-def";
144         char *sp;
145         x = strtok_r(s, "-", &sp);      // x = "abc", sp = "=-def"
146         x = strtok_r(NULL, "-=", &sp);  // x = "def", sp = NULL
147         x = strtok_r(NULL, "=", &sp);   // x = NULL
148                 // s = "abc\0-def\0"
149
150    This is a variant of strtok() that is multithread-safe.
151
152    For the POSIX documentation for this function, see:
153    http://www.opengroup.org/susv3xsh/strtok.html
154
155    Caveat: It modifies the original string.
156    Caveat: These functions cannot be used on constant strings.
157    Caveat: The identity of the delimiting character is lost.
158    Caveat: It doesn't work with multibyte strings unless all of the delimiter
159            characters are ASCII characters < 0x30.
160
161    See also strsep().  */
162 #if ! @HAVE_DECL_STRTOK_R@
163 char *strtok_r (char *restrict __s, char const *restrict __sep,
164                 char **restrict __lasts);
165 #endif
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif