]>
Commit | Line | Data |
---|---|---|
9a0a462c | 1 | /* Machine-independant string function optimizations. |
568035b7 | 2 | Copyright (C) 1997-2013 Free Software Foundation, Inc. |
9a0a462c UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
9a0a462c UD |
10 | |
11 | The GNU C Library 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 GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
9a0a462c | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
9a0a462c | 19 | |
61eb22d3 UD |
20 | #ifndef _STRING_H |
21 | # error "Never use <bits/string2.h> directly; include <string.h> instead." | |
22 | #endif | |
23 | ||
2bdd4ca6 | 24 | #ifndef __NO_STRING_INLINES |
9a0a462c UD |
25 | |
26 | /* Unlike the definitions in the header <bits/string.h> the | |
61952351 UD |
27 | definitions contained here are not optimized down to assembler |
28 | level. Those optimizations are not always a good idea since this | |
9a0a462c | 29 | means the code size increases a lot. Instead the definitions here |
61952351 UD |
30 | optimize some functions in a way which do not dramatically |
31 | increase the code size and which do not use assembler. The main | |
4a691b06 | 32 | trick is to use GCC's `__builtin_constant_p' function. |
9a0a462c UD |
33 | |
34 | Every function XXX which has a defined version in | |
61eb22d3 | 35 | <bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX |
9a0a462c UD |
36 | to make sure we don't get redefinitions. |
37 | ||
38 | We must use here macros instead of inline functions since the | |
49c091e5 | 39 | trick won't work with the latter. */ |
9a0a462c | 40 | |
9bbd7837 UD |
41 | #ifndef __STRING_INLINE |
42 | # ifdef __cplusplus | |
43 | # define __STRING_INLINE inline | |
44 | # else | |
b037a293 | 45 | # define __STRING_INLINE __extern_inline |
9bbd7837 | 46 | # endif |
9a0a462c UD |
47 | #endif |
48 | ||
61eb22d3 UD |
49 | #if _STRING_ARCH_unaligned |
50 | /* If we can do unaligned memory accesses we must know the endianess. */ | |
51 | # include <endian.h> | |
52 | # include <bits/types.h> | |
53 | ||
54 | # if __BYTE_ORDER == __LITTLE_ENDIAN | |
55 | # define __STRING2_SMALL_GET16(src, idx) \ | |
a784e502 UD |
56 | (((const unsigned char *) (const char *) (src))[idx + 1] << 8 \ |
57 | | ((const unsigned char *) (const char *) (src))[idx]) | |
61eb22d3 | 58 | # define __STRING2_SMALL_GET32(src, idx) \ |
a784e502 UD |
59 | (((((const unsigned char *) (const char *) (src))[idx + 3] << 8 \ |
60 | | ((const unsigned char *) (const char *) (src))[idx + 2]) << 8 \ | |
61 | | ((const unsigned char *) (const char *) (src))[idx + 1]) << 8 \ | |
62 | | ((const unsigned char *) (const char *) (src))[idx]) | |
61eb22d3 UD |
63 | # else |
64 | # define __STRING2_SMALL_GET16(src, idx) \ | |
a784e502 UD |
65 | (((const unsigned char *) (const char *) (src))[idx] << 8 \ |
66 | | ((const unsigned char *) (const char *) (src))[idx + 1]) | |
61eb22d3 | 67 | # define __STRING2_SMALL_GET32(src, idx) \ |
a784e502 UD |
68 | (((((const unsigned char *) (const char *) (src))[idx] << 8 \ |
69 | | ((const unsigned char *) (const char *) (src))[idx + 1]) << 8 \ | |
70 | | ((const unsigned char *) (const char *) (src))[idx + 2]) << 8 \ | |
71 | | ((const unsigned char *) (const char *) (src))[idx + 3]) | |
61eb22d3 UD |
72 | # endif |
73 | #else | |
74 | /* These are a few types we need for the optimizations if we cannot | |
75 | use unaligned memory accesses. */ | |
76 | # define __STRING2_COPY_TYPE(N) \ | |
fab6d621 | 77 | typedef struct { unsigned char __arr[N]; } \ |
87865838 | 78 | __attribute__ ((__packed__)) __STRING2_COPY_ARR##N |
61eb22d3 UD |
79 | __STRING2_COPY_TYPE (2); |
80 | __STRING2_COPY_TYPE (3); | |
81 | __STRING2_COPY_TYPE (4); | |
82 | __STRING2_COPY_TYPE (5); | |
83 | __STRING2_COPY_TYPE (6); | |
84 | __STRING2_COPY_TYPE (7); | |
85 | __STRING2_COPY_TYPE (8); | |
86 | # undef __STRING2_COPY_TYPE | |
87 | #endif | |
88 | ||
7ef90c15 UD |
89 | /* Dereferencing a pointer arg to run sizeof on it fails for the void |
90 | pointer case, so we use this instead. | |
91 | Note that __x is evaluated twice. */ | |
92 | #define __string2_1bptr_p(__x) \ | |
36ab45e1 | 93 | ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1) |
61eb22d3 UD |
94 | |
95 | /* Set N bytes of S to C. */ | |
3dbfd811 UD |
96 | #if !defined _HAVE_STRING_ARCH_memset |
97 | # if !__GNUC_PREREQ (3, 0) | |
98 | # if _STRING_ARCH_unaligned | |
99 | # define memset(s, c, n) \ | |
99434729 | 100 | (__extension__ (__builtin_constant_p (n) && (n) <= 16 \ |
c1d226e7 UD |
101 | ? ((n) == 1 \ |
102 | ? __memset_1 (s, c) \ | |
6c8f9de3 | 103 | : __memset_gc (s, c, n)) \ |
99434729 UD |
104 | : (__builtin_constant_p (c) && (c) == '\0' \ |
105 | ? ({ void *__s = (s); __bzero (__s, n); __s; }) \ | |
106 | : memset (s, c, n)))) | |
107 | ||
3dbfd811 | 108 | # define __memset_1(s, c) ({ void *__s = (s); \ |
6c8f9de3 | 109 | *((__uint8_t *) __s) = (__uint8_t) c; __s; }) |
c1d226e7 | 110 | |
3dbfd811 | 111 | # define __memset_gc(s, c, n) \ |
99434729 | 112 | ({ void *__s = (s); \ |
722c33bb UD |
113 | union { \ |
114 | unsigned int __ui; \ | |
115 | unsigned short int __usi; \ | |
116 | unsigned char __uc; \ | |
117 | } *__u = __s; \ | |
6c8f9de3 | 118 | __uint8_t __c = (__uint8_t) (c); \ |
722c33bb | 119 | \ |
99434729 | 120 | /* This `switch' statement will be removed at compile-time. */ \ |
b85697f6 | 121 | switch ((unsigned int) (n)) \ |
99434729 UD |
122 | { \ |
123 | case 15: \ | |
722c33bb | 124 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 125 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 126 | case 11: \ |
722c33bb | 127 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 128 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 129 | case 7: \ |
722c33bb | 130 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 131 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 132 | case 3: \ |
722c33bb | 133 | __u->__usi = (unsigned short int) __c * 0x0101; \ |
87843f15 | 134 | __u = __extension__ ((void *) __u + 2); \ |
722c33bb | 135 | __u->__uc = (unsigned char) __c; \ |
99434729 UD |
136 | break; \ |
137 | \ | |
138 | case 14: \ | |
722c33bb | 139 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 140 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 141 | case 10: \ |
722c33bb | 142 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 143 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 144 | case 6: \ |
722c33bb | 145 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 146 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 147 | case 2: \ |
722c33bb | 148 | __u->__usi = (unsigned short int) __c * 0x0101; \ |
99434729 UD |
149 | break; \ |
150 | \ | |
151 | case 13: \ | |
722c33bb | 152 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 153 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 154 | case 9: \ |
722c33bb | 155 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 156 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 157 | case 5: \ |
722c33bb | 158 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 159 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 160 | case 1: \ |
722c33bb | 161 | __u->__uc = (unsigned char) __c; \ |
99434729 UD |
162 | break; \ |
163 | \ | |
164 | case 16: \ | |
722c33bb | 165 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 166 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 167 | case 12: \ |
722c33bb | 168 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 169 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 170 | case 8: \ |
722c33bb | 171 | __u->__ui = __c * 0x01010101; \ |
87843f15 | 172 | __u = __extension__ ((void *) __u + 4); \ |
99434729 | 173 | case 4: \ |
722c33bb | 174 | __u->__ui = __c * 0x01010101; \ |
99434729 UD |
175 | case 0: \ |
176 | break; \ | |
177 | } \ | |
178 | \ | |
179 | __s; }) | |
3dbfd811 UD |
180 | # else |
181 | # define memset(s, c, n) \ | |
23f5f62d UD |
182 | (__extension__ (__builtin_constant_p (c) && (c) == '\0' \ |
183 | ? ({ void *__s = (s); __bzero (__s, n); __s; }) \ | |
184 | : memset (s, c, n))) | |
3dbfd811 | 185 | # endif |
23f5f62d UD |
186 | # endif |
187 | ||
3dbfd811 UD |
188 | /* GCC < 3.0 optimizes memset(s, 0, n) but not bzero(s, n). |
189 | The optimization is broken before EGCS 1.1. | |
190 | GCC 3.0+ has __builtin_bzero as well, but at least till GCC 3.4 | |
191 | if it decides to call the library function, it calls memset | |
192 | and not bzero. */ | |
722c33bb | 193 | # if __GNUC_PREREQ (2, 91) |
a97d1494 | 194 | # define __bzero(s, n) __builtin_memset (s, '\0', n) |
23f5f62d | 195 | # endif |
c1d226e7 | 196 | |
61eb22d3 | 197 | #endif |
9a0a462c UD |
198 | |
199 | ||
e7c5513d UD |
200 | /* Copy N bytes from SRC to DEST, returning pointer to byte following the |
201 | last copied. */ | |
202 | #ifdef __USE_GNU | |
61423e13 UD |
203 | # if !defined _HAVE_STRING_ARCH_mempcpy || defined _FORCE_INLINES |
204 | # ifndef _HAVE_STRING_ARCH_mempcpy | |
4a691b06 UD |
205 | # if __GNUC_PREREQ (3, 4) |
206 | # define __mempcpy(dest, src, n) __builtin_mempcpy (dest, src, n) | |
207 | # elif __GNUC_PREREQ (3, 0) | |
0295d266 UD |
208 | # define __mempcpy(dest, src, n) \ |
209 | (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \ | |
210 | && __string2_1bptr_p (src) && n <= 8 \ | |
9d7810d8 | 211 | ? __builtin_memcpy (dest, src, n) + (n) \ |
0295d266 UD |
212 | : __mempcpy (dest, src, n))) |
213 | # else | |
214 | # define __mempcpy(dest, src, n) \ | |
e7c5513d UD |
215 | (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \ |
216 | && __string2_1bptr_p (src) && n <= 8 \ | |
36ab45e1 | 217 | ? __mempcpy_small (dest, __mempcpy_args (src), n) \ |
e7c5513d | 218 | : __mempcpy (dest, src, n))) |
0295d266 | 219 | # endif |
e7c5513d UD |
220 | /* In glibc we use this function frequently but for namespace reasons |
221 | we have to use the name `__mempcpy'. */ | |
61423e13 UD |
222 | # define mempcpy(dest, src, n) __mempcpy (dest, src, n) |
223 | # endif | |
e7c5513d | 224 | |
0295d266 UD |
225 | # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES |
226 | # if _STRING_ARCH_unaligned | |
227 | # ifndef _FORCE_INLINES | |
228 | # define __mempcpy_args(src) \ | |
a784e502 UD |
229 | ((const char *) (src))[0], ((const char *) (src))[2], \ |
230 | ((const char *) (src))[4], ((const char *) (src))[6], \ | |
36ab45e1 UD |
231 | __extension__ __STRING2_SMALL_GET16 (src, 0), \ |
232 | __extension__ __STRING2_SMALL_GET16 (src, 4), \ | |
233 | __extension__ __STRING2_SMALL_GET32 (src, 0), \ | |
234 | __extension__ __STRING2_SMALL_GET32 (src, 4) | |
0295d266 | 235 | # endif |
fcab9698 UD |
236 | __STRING_INLINE void *__mempcpy_small (void *, char, char, char, char, |
237 | __uint16_t, __uint16_t, __uint32_t, | |
238 | __uint32_t, size_t); | |
36ab45e1 UD |
239 | __STRING_INLINE void * |
240 | __mempcpy_small (void *__dest1, | |
241 | char __src0_1, char __src2_1, char __src4_1, char __src6_1, | |
242 | __uint16_t __src0_2, __uint16_t __src4_2, | |
243 | __uint32_t __src0_4, __uint32_t __src4_4, | |
244 | size_t __srclen) | |
245 | { | |
722c33bb UD |
246 | union { |
247 | __uint32_t __ui; | |
248 | __uint16_t __usi; | |
249 | unsigned char __uc; | |
250 | unsigned char __c; | |
251 | } *__u = __dest1; | |
7eda722d | 252 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
253 | { |
254 | case 1: | |
722c33bb | 255 | __u->__c = __src0_1; |
87843f15 | 256 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
257 | break; |
258 | case 2: | |
722c33bb | 259 | __u->__usi = __src0_2; |
87843f15 | 260 | __u = __extension__ ((void *) __u + 2); |
36ab45e1 UD |
261 | break; |
262 | case 3: | |
722c33bb | 263 | __u->__usi = __src0_2; |
87843f15 | 264 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 265 | __u->__c = __src2_1; |
87843f15 | 266 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
267 | break; |
268 | case 4: | |
722c33bb | 269 | __u->__ui = __src0_4; |
87843f15 | 270 | __u = __extension__ ((void *) __u + 4); |
36ab45e1 UD |
271 | break; |
272 | case 5: | |
722c33bb | 273 | __u->__ui = __src0_4; |
87843f15 | 274 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 275 | __u->__c = __src4_1; |
87843f15 | 276 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
277 | break; |
278 | case 6: | |
722c33bb | 279 | __u->__ui = __src0_4; |
87843f15 | 280 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 281 | __u->__usi = __src4_2; |
87843f15 | 282 | __u = __extension__ ((void *) __u + 2); |
36ab45e1 UD |
283 | break; |
284 | case 7: | |
722c33bb | 285 | __u->__ui = __src0_4; |
87843f15 | 286 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 287 | __u->__usi = __src4_2; |
87843f15 | 288 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 289 | __u->__c = __src6_1; |
87843f15 | 290 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
291 | break; |
292 | case 8: | |
722c33bb | 293 | __u->__ui = __src0_4; |
87843f15 | 294 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 295 | __u->__ui = __src4_4; |
87843f15 | 296 | __u = __extension__ ((void *) __u + 4); |
36ab45e1 UD |
297 | break; |
298 | } | |
722c33bb | 299 | return (void *) __u; |
36ab45e1 | 300 | } |
0295d266 UD |
301 | # else |
302 | # ifndef _FORCE_INLINES | |
303 | # define __mempcpy_args(src) \ | |
a784e502 | 304 | ((const char *) (src))[0], \ |
36ab45e1 | 305 | __extension__ ((__STRING2_COPY_ARR2) \ |
a784e502 | 306 | { { ((const char *) (src))[0], ((const char *) (src))[1] } }), \ |
36ab45e1 | 307 | __extension__ ((__STRING2_COPY_ARR3) \ |
a784e502 UD |
308 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
309 | ((const char *) (src))[2] } }), \ | |
36ab45e1 | 310 | __extension__ ((__STRING2_COPY_ARR4) \ |
a784e502 UD |
311 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
312 | ((const char *) (src))[2], ((const char *) (src))[3] } }), \ | |
36ab45e1 | 313 | __extension__ ((__STRING2_COPY_ARR5) \ |
a784e502 UD |
314 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
315 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
316 | ((const char *) (src))[4] } }), \ | |
36ab45e1 | 317 | __extension__ ((__STRING2_COPY_ARR6) \ |
a784e502 UD |
318 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
319 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
320 | ((const char *) (src))[4], ((const char *) (src))[5] } }), \ | |
36ab45e1 | 321 | __extension__ ((__STRING2_COPY_ARR7) \ |
a784e502 UD |
322 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
323 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
324 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
325 | ((const char *) (src))[6] } }), \ | |
36ab45e1 | 326 | __extension__ ((__STRING2_COPY_ARR8) \ |
a784e502 UD |
327 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
328 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
329 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
330 | ((const char *) (src))[6], ((const char *) (src))[7] } }) | |
0295d266 | 331 | # endif |
fcab9698 UD |
332 | __STRING_INLINE void *__mempcpy_small (void *, char, __STRING2_COPY_ARR2, |
333 | __STRING2_COPY_ARR3, | |
334 | __STRING2_COPY_ARR4, | |
335 | __STRING2_COPY_ARR5, | |
336 | __STRING2_COPY_ARR6, | |
337 | __STRING2_COPY_ARR7, | |
338 | __STRING2_COPY_ARR8, size_t); | |
36ab45e1 | 339 | __STRING_INLINE void * |
722c33bb | 340 | __mempcpy_small (void *__dest, char __src1, |
36ab45e1 UD |
341 | __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3, |
342 | __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5, | |
343 | __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7, | |
344 | __STRING2_COPY_ARR8 __src8, size_t __srclen) | |
345 | { | |
722c33bb UD |
346 | union { |
347 | char __c; | |
348 | __STRING2_COPY_ARR2 __sca2; | |
349 | __STRING2_COPY_ARR3 __sca3; | |
350 | __STRING2_COPY_ARR4 __sca4; | |
351 | __STRING2_COPY_ARR5 __sca5; | |
352 | __STRING2_COPY_ARR6 __sca6; | |
353 | __STRING2_COPY_ARR7 __sca7; | |
354 | __STRING2_COPY_ARR8 __sca8; | |
355 | } *__u = __dest; | |
7eda722d | 356 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
357 | { |
358 | case 1: | |
722c33bb | 359 | __u->__c = __src1; |
36ab45e1 UD |
360 | break; |
361 | case 2: | |
722c33bb | 362 | __extension__ __u->__sca2 = __src2; |
36ab45e1 UD |
363 | break; |
364 | case 3: | |
722c33bb | 365 | __extension__ __u->__sca3 = __src3; |
36ab45e1 UD |
366 | break; |
367 | case 4: | |
722c33bb | 368 | __extension__ __u->__sca4 = __src4; |
36ab45e1 UD |
369 | break; |
370 | case 5: | |
722c33bb | 371 | __extension__ __u->__sca5 = __src5; |
36ab45e1 UD |
372 | break; |
373 | case 6: | |
722c33bb | 374 | __extension__ __u->__sca6 = __src6; |
36ab45e1 UD |
375 | break; |
376 | case 7: | |
722c33bb | 377 | __extension__ __u->__sca7 = __src7; |
36ab45e1 UD |
378 | break; |
379 | case 8: | |
722c33bb | 380 | __extension__ __u->__sca8 = __src8; |
36ab45e1 UD |
381 | break; |
382 | } | |
722c33bb | 383 | return __extension__ ((void *) __u + __srclen); |
36ab45e1 | 384 | } |
0295d266 | 385 | # endif |
e7c5513d UD |
386 | # endif |
387 | # endif | |
388 | #endif | |
389 | ||
390 | ||
482eec0d UD |
391 | /* Return pointer to C in S. */ |
392 | #ifndef _HAVE_STRING_ARCH_strchr | |
c1422e5b | 393 | extern void *__rawmemchr (const void *__s, int __c); |
4a691b06 UD |
394 | # if __GNUC_PREREQ (3, 2) |
395 | # define strchr(s, c) \ | |
396 | (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \ | |
397 | && (c) == '\0' \ | |
398 | ? (char *) __rawmemchr (s, c) \ | |
399 | : __builtin_strchr (s, c))) | |
400 | # else | |
401 | # define strchr(s, c) \ | |
482eec0d UD |
402 | (__extension__ (__builtin_constant_p (c) && (c) == '\0' \ |
403 | ? (char *) __rawmemchr (s, c) \ | |
404 | : strchr (s, c))) | |
4a691b06 | 405 | # endif |
482eec0d UD |
406 | #endif |
407 | ||
408 | ||
9a0a462c | 409 | /* Copy SRC to DEST. */ |
0295d266 UD |
410 | #if (!defined _HAVE_STRING_ARCH_strcpy && !__GNUC_PREREQ (3, 0)) \ |
411 | || defined _FORCE_INLINES | |
412 | # if !defined _HAVE_STRING_ARCH_strcpy && !__GNUC_PREREQ (3, 0) | |
61423e13 | 413 | # define strcpy(dest, src) \ |
9a0a462c | 414 | (__extension__ (__builtin_constant_p (src) \ |
dfd2257a | 415 | ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \ |
36ab45e1 UD |
416 | ? __strcpy_small (dest, __strcpy_args (src), \ |
417 | strlen (src) + 1) \ | |
9a0a462c UD |
418 | : (char *) memcpy (dest, src, strlen (src) + 1)) \ |
419 | : strcpy (dest, src))) | |
61423e13 | 420 | # endif |
9a0a462c | 421 | |
61eb22d3 | 422 | # if _STRING_ARCH_unaligned |
61423e13 UD |
423 | # ifndef _FORCE_INLINES |
424 | # define __strcpy_args(src) \ | |
36ab45e1 UD |
425 | __extension__ __STRING2_SMALL_GET16 (src, 0), \ |
426 | __extension__ __STRING2_SMALL_GET16 (src, 4), \ | |
427 | __extension__ __STRING2_SMALL_GET32 (src, 0), \ | |
428 | __extension__ __STRING2_SMALL_GET32 (src, 4) | |
61423e13 | 429 | # endif |
fcab9698 UD |
430 | __STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t, |
431 | __uint32_t, __uint32_t, size_t); | |
36ab45e1 UD |
432 | __STRING_INLINE char * |
433 | __strcpy_small (char *__dest, | |
434 | __uint16_t __src0_2, __uint16_t __src4_2, | |
435 | __uint32_t __src0_4, __uint32_t __src4_4, | |
436 | size_t __srclen) | |
437 | { | |
722c33bb UD |
438 | union { |
439 | __uint32_t __ui; | |
440 | __uint16_t __usi; | |
441 | unsigned char __uc; | |
442 | } *__u = (void *) __dest; | |
7eda722d | 443 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
444 | { |
445 | case 1: | |
722c33bb | 446 | __u->__uc = '\0'; |
36ab45e1 UD |
447 | break; |
448 | case 2: | |
722c33bb | 449 | __u->__usi = __src0_2; |
36ab45e1 UD |
450 | break; |
451 | case 3: | |
722c33bb | 452 | __u->__usi = __src0_2; |
87843f15 | 453 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 454 | __u->__uc = '\0'; |
36ab45e1 UD |
455 | break; |
456 | case 4: | |
722c33bb | 457 | __u->__ui = __src0_4; |
36ab45e1 UD |
458 | break; |
459 | case 5: | |
722c33bb | 460 | __u->__ui = __src0_4; |
87843f15 | 461 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 462 | __u->__uc = '\0'; |
36ab45e1 UD |
463 | break; |
464 | case 6: | |
722c33bb | 465 | __u->__ui = __src0_4; |
87843f15 | 466 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 467 | __u->__usi = __src4_2; |
36ab45e1 UD |
468 | break; |
469 | case 7: | |
722c33bb | 470 | __u->__ui = __src0_4; |
87843f15 | 471 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 472 | __u->__usi = __src4_2; |
87843f15 | 473 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 474 | __u->__uc = '\0'; |
36ab45e1 UD |
475 | break; |
476 | case 8: | |
722c33bb | 477 | __u->__ui = __src0_4; |
87843f15 | 478 | __u = __extension__ ((void *) __u + 4); |
83f6a990 | 479 | __u->__ui = __src4_4; |
36ab45e1 UD |
480 | break; |
481 | } | |
482 | return __dest; | |
483 | } | |
61eb22d3 | 484 | # else |
61423e13 UD |
485 | # ifndef _FORCE_INLINES |
486 | # define __strcpy_args(src) \ | |
36ab45e1 | 487 | __extension__ ((__STRING2_COPY_ARR2) \ |
a784e502 | 488 | { { ((const char *) (src))[0], '\0' } }), \ |
36ab45e1 | 489 | __extension__ ((__STRING2_COPY_ARR3) \ |
a784e502 | 490 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
36ab45e1 UD |
491 | '\0' } }), \ |
492 | __extension__ ((__STRING2_COPY_ARR4) \ | |
a784e502 UD |
493 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
494 | ((const char *) (src))[2], '\0' } }), \ | |
36ab45e1 | 495 | __extension__ ((__STRING2_COPY_ARR5) \ |
a784e502 UD |
496 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
497 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
36ab45e1 UD |
498 | '\0' } }), \ |
499 | __extension__ ((__STRING2_COPY_ARR6) \ | |
a784e502 UD |
500 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
501 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
502 | ((const char *) (src))[4], '\0' } }), \ | |
36ab45e1 | 503 | __extension__ ((__STRING2_COPY_ARR7) \ |
a784e502 UD |
504 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
505 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
506 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
36ab45e1 UD |
507 | '\0' } }), \ |
508 | __extension__ ((__STRING2_COPY_ARR8) \ | |
a784e502 UD |
509 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
510 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
511 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
512 | ((const char *) (src))[6], '\0' } }) | |
61423e13 | 513 | # endif |
fcab9698 UD |
514 | __STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2, |
515 | __STRING2_COPY_ARR3, | |
516 | __STRING2_COPY_ARR4, | |
517 | __STRING2_COPY_ARR5, | |
518 | __STRING2_COPY_ARR6, | |
519 | __STRING2_COPY_ARR7, | |
520 | __STRING2_COPY_ARR8, size_t); | |
36ab45e1 UD |
521 | __STRING_INLINE char * |
522 | __strcpy_small (char *__dest, | |
523 | __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3, | |
524 | __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5, | |
525 | __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7, | |
526 | __STRING2_COPY_ARR8 __src8, size_t __srclen) | |
527 | { | |
722c33bb UD |
528 | union { |
529 | char __c; | |
530 | __STRING2_COPY_ARR2 __sca2; | |
531 | __STRING2_COPY_ARR3 __sca3; | |
532 | __STRING2_COPY_ARR4 __sca4; | |
533 | __STRING2_COPY_ARR5 __sca5; | |
534 | __STRING2_COPY_ARR6 __sca6; | |
535 | __STRING2_COPY_ARR7 __sca7; | |
536 | __STRING2_COPY_ARR8 __sca8; | |
b18ac18e | 537 | } *__u = (void *) __dest; |
7eda722d | 538 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
539 | { |
540 | case 1: | |
722c33bb | 541 | __u->__c = '\0'; |
36ab45e1 UD |
542 | break; |
543 | case 2: | |
722c33bb | 544 | __extension__ __u->__sca2 = __src2; |
36ab45e1 UD |
545 | break; |
546 | case 3: | |
722c33bb | 547 | __extension__ __u->__sca3 = __src3; |
36ab45e1 UD |
548 | break; |
549 | case 4: | |
722c33bb | 550 | __extension__ __u->__sca4 = __src4; |
36ab45e1 UD |
551 | break; |
552 | case 5: | |
722c33bb | 553 | __extension__ __u->__sca5 = __src5; |
36ab45e1 UD |
554 | break; |
555 | case 6: | |
722c33bb | 556 | __extension__ __u->__sca6 = __src6; |
36ab45e1 UD |
557 | break; |
558 | case 7: | |
722c33bb | 559 | __extension__ __u->__sca7 = __src7; |
36ab45e1 UD |
560 | break; |
561 | case 8: | |
722c33bb | 562 | __extension__ __u->__sca8 = __src8; |
36ab45e1 UD |
563 | break; |
564 | } | |
565 | return __dest; | |
566 | } | |
61eb22d3 | 567 | # endif |
9a0a462c UD |
568 | #endif |
569 | ||
570 | ||
571 | /* Copy SRC to DEST, returning pointer to final NUL byte. */ | |
572 | #ifdef __USE_GNU | |
61423e13 UD |
573 | # if !defined _HAVE_STRING_ARCH_stpcpy || defined _FORCE_INLINES |
574 | # ifndef _HAVE_STRING_ARCH_stpcpy | |
4a691b06 UD |
575 | # if __GNUC_PREREQ (3, 4) |
576 | # define __stpcpy(dest, src) __builtin_stpcpy (dest, src) | |
577 | # elif __GNUC_PREREQ (3, 0) | |
0295d266 UD |
578 | # define __stpcpy(dest, src) \ |
579 | (__extension__ (__builtin_constant_p (src) \ | |
580 | ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \ | |
581 | ? __builtin_strcpy (dest, src) + strlen (src) \ | |
582 | : ((char *) (__mempcpy) (dest, src, strlen (src) + 1) \ | |
583 | - 1)) \ | |
584 | : __stpcpy (dest, src))) | |
585 | # else | |
586 | # define __stpcpy(dest, src) \ | |
9a0a462c | 587 | (__extension__ (__builtin_constant_p (src) \ |
dfd2257a | 588 | ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \ |
36ab45e1 UD |
589 | ? __stpcpy_small (dest, __stpcpy_args (src), \ |
590 | strlen (src) + 1) \ | |
0295d266 UD |
591 | : ((char *) (__mempcpy) (dest, src, strlen (src) + 1) \ |
592 | - 1)) \ | |
9a0a462c | 593 | : __stpcpy (dest, src))) |
0295d266 | 594 | # endif |
9a0a462c UD |
595 | /* In glibc we use this function frequently but for namespace reasons |
596 | we have to use the name `__stpcpy'. */ | |
61423e13 UD |
597 | # define stpcpy(dest, src) __stpcpy (dest, src) |
598 | # endif | |
9a0a462c | 599 | |
b45b9457 | 600 | # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES |
0295d266 UD |
601 | # if _STRING_ARCH_unaligned |
602 | # ifndef _FORCE_INLINES | |
603 | # define __stpcpy_args(src) \ | |
36ab45e1 UD |
604 | __extension__ __STRING2_SMALL_GET16 (src, 0), \ |
605 | __extension__ __STRING2_SMALL_GET16 (src, 4), \ | |
606 | __extension__ __STRING2_SMALL_GET32 (src, 0), \ | |
607 | __extension__ __STRING2_SMALL_GET32 (src, 4) | |
0295d266 | 608 | # endif |
fcab9698 UD |
609 | __STRING_INLINE char *__stpcpy_small (char *, __uint16_t, __uint16_t, |
610 | __uint32_t, __uint32_t, size_t); | |
36ab45e1 UD |
611 | __STRING_INLINE char * |
612 | __stpcpy_small (char *__dest, | |
613 | __uint16_t __src0_2, __uint16_t __src4_2, | |
614 | __uint32_t __src0_4, __uint32_t __src4_4, | |
615 | size_t __srclen) | |
616 | { | |
722c33bb UD |
617 | union { |
618 | unsigned int __ui; | |
619 | unsigned short int __usi; | |
620 | unsigned char __uc; | |
3e1e749e | 621 | char __c; |
722c33bb | 622 | } *__u = (void *) __dest; |
7eda722d | 623 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
624 | { |
625 | case 1: | |
722c33bb | 626 | __u->__uc = '\0'; |
36ab45e1 UD |
627 | break; |
628 | case 2: | |
722c33bb | 629 | __u->__usi = __src0_2; |
87843f15 | 630 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
631 | break; |
632 | case 3: | |
722c33bb | 633 | __u->__usi = __src0_2; |
87843f15 | 634 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 635 | __u->__uc = '\0'; |
36ab45e1 UD |
636 | break; |
637 | case 4: | |
722c33bb | 638 | __u->__ui = __src0_4; |
87843f15 | 639 | __u = __extension__ ((void *) __u + 3); |
36ab45e1 UD |
640 | break; |
641 | case 5: | |
722c33bb | 642 | __u->__ui = __src0_4; |
87843f15 | 643 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 644 | __u->__uc = '\0'; |
36ab45e1 UD |
645 | break; |
646 | case 6: | |
722c33bb | 647 | __u->__ui = __src0_4; |
87843f15 | 648 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 649 | __u->__usi = __src4_2; |
87843f15 | 650 | __u = __extension__ ((void *) __u + 1); |
36ab45e1 UD |
651 | break; |
652 | case 7: | |
722c33bb | 653 | __u->__ui = __src0_4; |
87843f15 | 654 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 655 | __u->__usi = __src4_2; |
87843f15 | 656 | __u = __extension__ ((void *) __u + 2); |
722c33bb | 657 | __u->__uc = '\0'; |
36ab45e1 UD |
658 | break; |
659 | case 8: | |
722c33bb | 660 | __u->__ui = __src0_4; |
87843f15 | 661 | __u = __extension__ ((void *) __u + 4); |
722c33bb | 662 | __u->__ui = __src4_4; |
87843f15 | 663 | __u = __extension__ ((void *) __u + 3); |
36ab45e1 UD |
664 | break; |
665 | } | |
3e1e749e | 666 | return &__u->__c; |
36ab45e1 | 667 | } |
0295d266 UD |
668 | # else |
669 | # ifndef _FORCE_INLINES | |
670 | # define __stpcpy_args(src) \ | |
36ab45e1 | 671 | __extension__ ((__STRING2_COPY_ARR2) \ |
a784e502 | 672 | { { ((const char *) (src))[0], '\0' } }), \ |
36ab45e1 | 673 | __extension__ ((__STRING2_COPY_ARR3) \ |
a784e502 | 674 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
36ab45e1 UD |
675 | '\0' } }), \ |
676 | __extension__ ((__STRING2_COPY_ARR4) \ | |
a784e502 UD |
677 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
678 | ((const char *) (src))[2], '\0' } }), \ | |
36ab45e1 | 679 | __extension__ ((__STRING2_COPY_ARR5) \ |
a784e502 UD |
680 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
681 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
36ab45e1 UD |
682 | '\0' } }), \ |
683 | __extension__ ((__STRING2_COPY_ARR6) \ | |
a784e502 UD |
684 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
685 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
686 | ((const char *) (src))[4], '\0' } }), \ | |
36ab45e1 | 687 | __extension__ ((__STRING2_COPY_ARR7) \ |
a784e502 UD |
688 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
689 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
690 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
36ab45e1 UD |
691 | '\0' } }), \ |
692 | __extension__ ((__STRING2_COPY_ARR8) \ | |
a784e502 UD |
693 | { { ((const char *) (src))[0], ((const char *) (src))[1], \ |
694 | ((const char *) (src))[2], ((const char *) (src))[3], \ | |
695 | ((const char *) (src))[4], ((const char *) (src))[5], \ | |
696 | ((const char *) (src))[6], '\0' } }) | |
0295d266 | 697 | # endif |
fcab9698 UD |
698 | __STRING_INLINE char *__stpcpy_small (char *, __STRING2_COPY_ARR2, |
699 | __STRING2_COPY_ARR3, | |
700 | __STRING2_COPY_ARR4, | |
701 | __STRING2_COPY_ARR5, | |
702 | __STRING2_COPY_ARR6, | |
703 | __STRING2_COPY_ARR7, | |
704 | __STRING2_COPY_ARR8, size_t); | |
36ab45e1 UD |
705 | __STRING_INLINE char * |
706 | __stpcpy_small (char *__dest, | |
707 | __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3, | |
708 | __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5, | |
709 | __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7, | |
710 | __STRING2_COPY_ARR8 __src8, size_t __srclen) | |
711 | { | |
722c33bb UD |
712 | union { |
713 | char __c; | |
714 | __STRING2_COPY_ARR2 __sca2; | |
715 | __STRING2_COPY_ARR3 __sca3; | |
716 | __STRING2_COPY_ARR4 __sca4; | |
717 | __STRING2_COPY_ARR5 __sca5; | |
718 | __STRING2_COPY_ARR6 __sca6; | |
719 | __STRING2_COPY_ARR7 __sca7; | |
720 | __STRING2_COPY_ARR8 __sca8; | |
b18ac18e | 721 | } *__u = (void *) __dest; |
7eda722d | 722 | switch ((unsigned int) __srclen) |
36ab45e1 UD |
723 | { |
724 | case 1: | |
b18ac18e | 725 | __u->__c = '\0'; |
36ab45e1 UD |
726 | break; |
727 | case 2: | |
722c33bb | 728 | __extension__ __u->__sca2 = __src2; |
36ab45e1 UD |
729 | break; |
730 | case 3: | |
722c33bb | 731 | __extension__ __u->__sca3 = __src3; |
36ab45e1 UD |
732 | break; |
733 | case 4: | |
722c33bb | 734 | __extension__ __u->__sca4 = __src4; |
36ab45e1 UD |
735 | break; |
736 | case 5: | |
722c33bb | 737 | __extension__ __u->__sca5 = __src5; |
36ab45e1 UD |
738 | break; |
739 | case 6: | |
722c33bb | 740 | __extension__ __u->__sca6 = __src6; |
36ab45e1 UD |
741 | break; |
742 | case 7: | |
722c33bb | 743 | __extension__ __u->__sca7 = __src7; |
36ab45e1 UD |
744 | break; |
745 | case 8: | |
722c33bb | 746 | __extension__ __u->__sca8 = __src8; |
36ab45e1 UD |
747 | break; |
748 | } | |
749 | return __dest + __srclen - 1; | |
750 | } | |
0295d266 | 751 | # endif |
61eb22d3 | 752 | # endif |
9a0a462c UD |
753 | # endif |
754 | #endif | |
755 | ||
756 | ||
757 | /* Copy no more than N characters of SRC to DEST. */ | |
758 | #ifndef _HAVE_STRING_ARCH_strncpy | |
4a691b06 UD |
759 | # if __GNUC_PREREQ (3, 2) |
760 | # define strncpy(dest, src, n) __builtin_strncpy (dest, src, n) | |
9a0a462c UD |
761 | # else |
762 | # define strncpy(dest, src, n) \ | |
763 | (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \ | |
764 | ? (strlen (src) + 1 >= ((size_t) (n)) \ | |
765 | ? (char *) memcpy (dest, src, n) \ | |
766 | : strncpy (dest, src, n)) \ | |
767 | : strncpy (dest, src, n))) | |
768 | # endif | |
769 | #endif | |
770 | ||
771 | ||
772 | /* Append no more than N characters from SRC onto DEST. */ | |
773 | #ifndef _HAVE_STRING_ARCH_strncat | |
d3d99893 | 774 | # ifdef _USE_STRING_ARCH_strchr |
9a0a462c | 775 | # define strncat(dest, src, n) \ |
650425ce UD |
776 | (__extension__ ({ char *__dest = (dest); \ |
777 | __builtin_constant_p (src) && __builtin_constant_p (n) \ | |
778 | ? (strlen (src) < ((size_t) (n)) \ | |
779 | ? strcat (__dest, src) \ | |
9c3b1ceb UD |
780 | : (*((char *) __mempcpy (strchr (__dest, '\0'), \ |
781 | src, n)) = '\0', __dest)) \ | |
650425ce | 782 | : strncat (dest, src, n); })) |
4a691b06 UD |
783 | # elif __GNUC_PREREQ (3, 2) |
784 | # define strncat(dest, src, n) __builtin_strncat (dest, src, n) | |
9a0a462c UD |
785 | # else |
786 | # define strncat(dest, src, n) \ | |
787 | (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \ | |
788 | ? (strlen (src) < ((size_t) (n)) \ | |
789 | ? strcat (dest, src) \ | |
790 | : strncat (dest, src, n)) \ | |
791 | : strncat (dest, src, n))) | |
792 | # endif | |
793 | #endif | |
794 | ||
795 | ||
650425ce UD |
796 | /* Compare characters of S1 and S2. */ |
797 | #ifndef _HAVE_STRING_ARCH_strcmp | |
4a691b06 UD |
798 | # if __GNUC_PREREQ (3, 2) |
799 | # define strcmp(s1, s2) \ | |
800 | __extension__ \ | |
801 | ({ size_t __s1_len, __s2_len; \ | |
802 | (__builtin_constant_p (s1) && __builtin_constant_p (s2) \ | |
803 | && (__s1_len = strlen (s1), __s2_len = strlen (s2), \ | |
804 | (!__string2_1bptr_p (s1) || __s1_len >= 4) \ | |
805 | && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \ | |
806 | ? __builtin_strcmp (s1, s2) \ | |
807 | : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \ | |
808 | && (__s1_len = strlen (s1), __s1_len < 4) \ | |
809 | ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \ | |
810 | ? __builtin_strcmp (s1, s2) \ | |
811 | : __strcmp_cg (s1, s2, __s1_len)) \ | |
812 | : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \ | |
813 | && (__s2_len = strlen (s2), __s2_len < 4) \ | |
814 | ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \ | |
815 | ? __builtin_strcmp (s1, s2) \ | |
816 | : __strcmp_gc (s1, s2, __s2_len)) \ | |
817 | : __builtin_strcmp (s1, s2)))); }) | |
818 | # else | |
819 | # define strcmp(s1, s2) \ | |
36ab45e1 UD |
820 | __extension__ \ |
821 | ({ size_t __s1_len, __s2_len; \ | |
fcab9698 | 822 | (__builtin_constant_p (s1) && __builtin_constant_p (s2) \ |
36ab45e1 UD |
823 | && (__s1_len = strlen (s1), __s2_len = strlen (s2), \ |
824 | (!__string2_1bptr_p (s1) || __s1_len >= 4) \ | |
825 | && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \ | |
a784e502 | 826 | ? memcmp ((const char *) (s1), (const char *) (s2), \ |
36ab45e1 | 827 | (__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \ |
fcab9698 | 828 | : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \ |
36ab45e1 | 829 | && (__s1_len = strlen (s1), __s1_len < 4) \ |
fcab9698 | 830 | ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \ |
36ab45e1 UD |
831 | ? __strcmp_cc (s1, s2, __s1_len) \ |
832 | : __strcmp_cg (s1, s2, __s1_len)) \ | |
fcab9698 | 833 | : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \ |
36ab45e1 | 834 | && (__s2_len = strlen (s2), __s2_len < 4) \ |
fcab9698 | 835 | ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \ |
36ab45e1 UD |
836 | ? __strcmp_cc (s1, s2, __s2_len) \ |
837 | : __strcmp_gc (s1, s2, __s2_len)) \ | |
838 | : strcmp (s1, s2)))); }) | |
4a691b06 | 839 | # endif |
650425ce | 840 | |
a5a0310d | 841 | # define __strcmp_cc(s1, s2, l) \ |
af6f3906 | 842 | (__extension__ ({ register int __result = \ |
a784e502 UD |
843 | (((const unsigned char *) (const char *) (s1))[0] \ |
844 | - ((const unsigned char *) (const char *)(s2))[0]); \ | |
a5a0310d UD |
845 | if (l > 0 && __result == 0) \ |
846 | { \ | |
a784e502 UD |
847 | __result = (((const unsigned char *) \ |
848 | (const char *) (s1))[1] \ | |
849 | - ((const unsigned char *) \ | |
850 | (const char *) (s2))[1]); \ | |
a5a0310d UD |
851 | if (l > 1 && __result == 0) \ |
852 | { \ | |
af6f3906 | 853 | __result = \ |
a784e502 UD |
854 | (((const unsigned char *) \ |
855 | (const char *) (s1))[2] \ | |
856 | - ((const unsigned char *) \ | |
857 | (const char *) (s2))[2]); \ | |
a5a0310d | 858 | if (l > 2 && __result == 0) \ |
af6f3906 | 859 | __result = \ |
a784e502 UD |
860 | (((const unsigned char *) \ |
861 | (const char *) (s1))[3] \ | |
862 | - ((const unsigned char *) \ | |
863 | (const char *) (s2))[3]); \ | |
a5a0310d UD |
864 | } \ |
865 | } \ | |
866 | __result; })) | |
867 | ||
650425ce | 868 | # define __strcmp_cg(s1, s2, l1) \ |
a784e502 UD |
869 | (__extension__ ({ const unsigned char *__s2 = \ |
870 | (const unsigned char *) (const char *) (s2); \ | |
af6f3906 | 871 | register int __result = \ |
a784e502 | 872 | (((const unsigned char *) (const char *) (s1))[0] \ |
fab6d621 | 873 | - __s2[0]); \ |
650425ce UD |
874 | if (l1 > 0 && __result == 0) \ |
875 | { \ | |
a784e502 UD |
876 | __result = (((const unsigned char *) \ |
877 | (const char *) (s1))[1] - __s2[1]); \ | |
650425ce UD |
878 | if (l1 > 1 && __result == 0) \ |
879 | { \ | |
a784e502 UD |
880 | __result = (((const unsigned char *) \ |
881 | (const char *) (s1))[2] - __s2[2]); \ | |
650425ce | 882 | if (l1 > 2 && __result == 0) \ |
a784e502 UD |
883 | __result = (((const unsigned char *) \ |
884 | (const char *) (s1))[3] \ | |
af6f3906 | 885 | - __s2[3]); \ |
650425ce UD |
886 | } \ |
887 | } \ | |
888 | __result; })) | |
889 | ||
890 | # define __strcmp_gc(s1, s2, l2) \ | |
a784e502 UD |
891 | (__extension__ ({ const unsigned char *__s1 = \ |
892 | (const unsigned char *) (const char *) (s1); \ | |
af6f3906 | 893 | register int __result = \ |
a784e502 UD |
894 | __s1[0] - ((const unsigned char *) \ |
895 | (const char *) (s2))[0]; \ | |
650425ce UD |
896 | if (l2 > 0 && __result == 0) \ |
897 | { \ | |
af6f3906 | 898 | __result = (__s1[1] \ |
a784e502 UD |
899 | - ((const unsigned char *) \ |
900 | (const char *) (s2))[1]); \ | |
650425ce UD |
901 | if (l2 > 1 && __result == 0) \ |
902 | { \ | |
af6f3906 | 903 | __result = \ |
a784e502 UD |
904 | (__s1[2] - ((const unsigned char *) \ |
905 | (const char *) (s2))[2]); \ | |
650425ce | 906 | if (l2 > 2 && __result == 0) \ |
af6f3906 UD |
907 | __result = \ |
908 | (__s1[3] \ | |
a784e502 UD |
909 | - ((const unsigned char *) \ |
910 | (const char *) (s2))[3]); \ | |
650425ce UD |
911 | } \ |
912 | } \ | |
913 | __result; })) | |
914 | #endif | |
915 | ||
916 | ||
9a0a462c UD |
917 | /* Compare N characters of S1 and S2. */ |
918 | #ifndef _HAVE_STRING_ARCH_strncmp | |
d30da2a8 UD |
919 | # define strncmp(s1, s2, n) \ |
920 | (__extension__ (__builtin_constant_p (n) \ | |
921 | && ((__builtin_constant_p (s1) \ | |
922 | && strlen (s1) < ((size_t) (n))) \ | |
923 | || (__builtin_constant_p (s2) \ | |
924 | && strlen (s2) < ((size_t) (n)))) \ | |
925 | ? strcmp (s1, s2) : strncmp (s1, s2, n))) | |
9a0a462c UD |
926 | #endif |
927 | ||
928 | ||
929 | /* Return the length of the initial segment of S which | |
930 | consists entirely of characters not in REJECT. */ | |
61423e13 UD |
931 | #if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES |
932 | # ifndef _HAVE_STRING_ARCH_strcspn | |
4a691b06 UD |
933 | # if __GNUC_PREREQ (3, 2) |
934 | # define strcspn(s, reject) \ | |
935 | __extension__ \ | |
936 | ({ char __r0, __r1, __r2; \ | |
937 | (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \ | |
938 | ? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \ | |
939 | ? __builtin_strcspn (s, reject) \ | |
a784e502 | 940 | : ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \ |
4a691b06 | 941 | ? strlen (s) \ |
a784e502 | 942 | : ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \ |
4a691b06 | 943 | ? __strcspn_c1 (s, __r0) \ |
a784e502 | 944 | : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \ |
4a691b06 | 945 | ? __strcspn_c2 (s, __r0, __r1) \ |
a784e502 | 946 | : (((const char *) (reject))[3] == '\0' \ |
4a691b06 UD |
947 | ? __strcspn_c3 (s, __r0, __r1, __r2) \ |
948 | : __builtin_strcspn (s, reject)))))) \ | |
949 | : __builtin_strcspn (s, reject)); }) | |
950 | # else | |
951 | # define strcspn(s, reject) \ | |
36ab45e1 UD |
952 | __extension__ \ |
953 | ({ char __r0, __r1, __r2; \ | |
954 | (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \ | |
a784e502 | 955 | ? ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \ |
36ab45e1 | 956 | ? strlen (s) \ |
a784e502 | 957 | : ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \ |
36ab45e1 | 958 | ? __strcspn_c1 (s, __r0) \ |
a784e502 | 959 | : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \ |
36ab45e1 | 960 | ? __strcspn_c2 (s, __r0, __r1) \ |
a784e502 | 961 | : (((const char *) (reject))[3] == '\0' \ |
36ab45e1 UD |
962 | ? __strcspn_c3 (s, __r0, __r1, __r2) \ |
963 | : strcspn (s, reject))))) \ | |
4a691b06 UD |
964 | : strcspn (s, reject)); }) |
965 | # endif | |
61423e13 | 966 | # endif |
9a0a462c | 967 | |
a784e502 | 968 | __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject); |
9a0a462c | 969 | __STRING_INLINE size_t |
a784e502 | 970 | __strcspn_c1 (const char *__s, int __reject) |
9a0a462c UD |
971 | { |
972 | register size_t __result = 0; | |
973 | while (__s[__result] != '\0' && __s[__result] != __reject) | |
974 | ++__result; | |
975 | return __result; | |
976 | } | |
14c44e2e | 977 | |
a784e502 | 978 | __STRING_INLINE size_t __strcspn_c2 (const char *__s, int __reject1, |
61423e13 | 979 | int __reject2); |
14c44e2e | 980 | __STRING_INLINE size_t |
a784e502 | 981 | __strcspn_c2 (const char *__s, int __reject1, int __reject2) |
14c44e2e UD |
982 | { |
983 | register size_t __result = 0; | |
984 | while (__s[__result] != '\0' && __s[__result] != __reject1 | |
985 | && __s[__result] != __reject2) | |
986 | ++__result; | |
987 | return __result; | |
988 | } | |
989 | ||
a784e502 | 990 | __STRING_INLINE size_t __strcspn_c3 (const char *__s, int __reject1, |
61423e13 | 991 | int __reject2, int __reject3); |
14c44e2e | 992 | __STRING_INLINE size_t |
a784e502 | 993 | __strcspn_c3 (const char *__s, int __reject1, int __reject2, |
61423e13 | 994 | int __reject3) |
14c44e2e UD |
995 | { |
996 | register size_t __result = 0; | |
997 | while (__s[__result] != '\0' && __s[__result] != __reject1 | |
998 | && __s[__result] != __reject2 && __s[__result] != __reject3) | |
999 | ++__result; | |
1000 | return __result; | |
1001 | } | |
9a0a462c UD |
1002 | #endif |
1003 | ||
1004 | ||
1005 | /* Return the length of the initial segment of S which | |
1006 | consists entirely of characters in ACCEPT. */ | |
61423e13 UD |
1007 | #if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES |
1008 | # ifndef _HAVE_STRING_ARCH_strspn | |
4a691b06 UD |
1009 | # if __GNUC_PREREQ (3, 2) |
1010 | # define strspn(s, accept) \ | |
1011 | __extension__ \ | |
1012 | ({ char __a0, __a1, __a2; \ | |
1013 | (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \ | |
1014 | ? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \ | |
1015 | ? __builtin_strspn (s, accept) \ | |
a784e502 | 1016 | : ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \ |
1a4b75a1 | 1017 | ? ((void) (s), (size_t) 0) \ |
a784e502 | 1018 | : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \ |
4a691b06 | 1019 | ? __strspn_c1 (s, __a0) \ |
a784e502 | 1020 | : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \ |
4a691b06 | 1021 | ? __strspn_c2 (s, __a0, __a1) \ |
a784e502 | 1022 | : (((const char *) (accept))[3] == '\0' \ |
4a691b06 UD |
1023 | ? __strspn_c3 (s, __a0, __a1, __a2) \ |
1024 | : __builtin_strspn (s, accept)))))) \ | |
1025 | : __builtin_strspn (s, accept)); }) | |
1026 | # else | |
1027 | # define strspn(s, accept) \ | |
36ab45e1 UD |
1028 | __extension__ \ |
1029 | ({ char __a0, __a1, __a2; \ | |
1030 | (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \ | |
a784e502 | 1031 | ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \ |
1a4b75a1 | 1032 | ? ((void) (s), (size_t) 0) \ |
a784e502 | 1033 | : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \ |
36ab45e1 | 1034 | ? __strspn_c1 (s, __a0) \ |
a784e502 | 1035 | : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \ |
36ab45e1 | 1036 | ? __strspn_c2 (s, __a0, __a1) \ |
a784e502 | 1037 | : (((const char *) (accept))[3] == '\0' \ |
36ab45e1 UD |
1038 | ? __strspn_c3 (s, __a0, __a1, __a2) \ |
1039 | : strspn (s, accept))))) \ | |
1040 | : strspn (s, accept)); }) | |
4a691b06 | 1041 | # endif |
61423e13 | 1042 | # endif |
9a0a462c | 1043 | |
a784e502 | 1044 | __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept); |
9a0a462c | 1045 | __STRING_INLINE size_t |
a784e502 | 1046 | __strspn_c1 (const char *__s, int __accept) |
9a0a462c UD |
1047 | { |
1048 | register size_t __result = 0; | |
1049 | /* Please note that __accept never can be '\0'. */ | |
1050 | while (__s[__result] == __accept) | |
1051 | ++__result; | |
1052 | return __result; | |
1053 | } | |
14c44e2e | 1054 | |
a784e502 | 1055 | __STRING_INLINE size_t __strspn_c2 (const char *__s, int __accept1, |
61423e13 | 1056 | int __accept2); |
14c44e2e | 1057 | __STRING_INLINE size_t |
a784e502 | 1058 | __strspn_c2 (const char *__s, int __accept1, int __accept2) |
14c44e2e UD |
1059 | { |
1060 | register size_t __result = 0; | |
1061 | /* Please note that __accept1 and __accept2 never can be '\0'. */ | |
1062 | while (__s[__result] == __accept1 || __s[__result] == __accept2) | |
1063 | ++__result; | |
1064 | return __result; | |
1065 | } | |
1066 | ||
a784e502 | 1067 | __STRING_INLINE size_t __strspn_c3 (const char *__s, int __accept1, |
61423e13 | 1068 | int __accept2, int __accept3); |
14c44e2e | 1069 | __STRING_INLINE size_t |
a784e502 | 1070 | __strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3) |
14c44e2e UD |
1071 | { |
1072 | register size_t __result = 0; | |
1073 | /* Please note that __accept1 to __accept3 never can be '\0'. */ | |
1074 | while (__s[__result] == __accept1 || __s[__result] == __accept2 | |
1075 | || __s[__result] == __accept3) | |
1076 | ++__result; | |
1077 | return __result; | |
1078 | } | |
9a0a462c UD |
1079 | #endif |
1080 | ||
1081 | ||
1082 | /* Find the first occurrence in S of any character in ACCEPT. */ | |
61423e13 UD |
1083 | #if !defined _HAVE_STRING_ARCH_strpbrk || defined _FORCE_INLINES |
1084 | # ifndef _HAVE_STRING_ARCH_strpbrk | |
4a691b06 UD |
1085 | # if __GNUC_PREREQ (3, 2) |
1086 | # define strpbrk(s, accept) \ | |
1087 | __extension__ \ | |
1088 | ({ char __a0, __a1, __a2; \ | |
1089 | (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \ | |
1090 | ? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \ | |
1091 | ? __builtin_strpbrk (s, accept) \ | |
a784e502 | 1092 | : ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \ |
4a691b06 | 1093 | ? ((void) (s), (char *) NULL) \ |
a784e502 | 1094 | : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \ |
4a691b06 | 1095 | ? __builtin_strchr (s, __a0) \ |
a784e502 | 1096 | : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \ |
4a691b06 | 1097 | ? __strpbrk_c2 (s, __a0, __a1) \ |
a784e502 | 1098 | : (((const char *) (accept))[3] == '\0' \ |
4a691b06 UD |
1099 | ? __strpbrk_c3 (s, __a0, __a1, __a2) \ |
1100 | : __builtin_strpbrk (s, accept)))))) \ | |
1101 | : __builtin_strpbrk (s, accept)); }) | |
1102 | # else | |
1103 | # define strpbrk(s, accept) \ | |
36ab45e1 UD |
1104 | __extension__ \ |
1105 | ({ char __a0, __a1, __a2; \ | |
1106 | (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \ | |
a784e502 | 1107 | ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \ |
6f0b2e1f | 1108 | ? ((void) (s), (char *) NULL) \ |
a784e502 | 1109 | : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \ |
36ab45e1 | 1110 | ? strchr (s, __a0) \ |
a784e502 | 1111 | : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \ |
36ab45e1 | 1112 | ? __strpbrk_c2 (s, __a0, __a1) \ |
a784e502 | 1113 | : (((const char *) (accept))[3] == '\0' \ |
36ab45e1 UD |
1114 | ? __strpbrk_c3 (s, __a0, __a1, __a2) \ |
1115 | : strpbrk (s, accept))))) \ | |
1116 | : strpbrk (s, accept)); }) | |
4a691b06 | 1117 | # endif |
61423e13 | 1118 | # endif |
14c44e2e | 1119 | |
a784e502 UD |
1120 | __STRING_INLINE char *__strpbrk_c2 (const char *__s, int __accept1, |
1121 | int __accept2); | |
14c44e2e | 1122 | __STRING_INLINE char * |
a784e502 | 1123 | __strpbrk_c2 (const char *__s, int __accept1, int __accept2) |
14c44e2e UD |
1124 | { |
1125 | /* Please note that __accept1 and __accept2 never can be '\0'. */ | |
1126 | while (*__s != '\0' && *__s != __accept1 && *__s != __accept2) | |
1127 | ++__s; | |
d2537a47 | 1128 | return *__s == '\0' ? NULL : (char *) (size_t) __s; |
14c44e2e UD |
1129 | } |
1130 | ||
a784e502 UD |
1131 | __STRING_INLINE char *__strpbrk_c3 (const char *__s, int __accept1, |
1132 | int __accept2, int __accept3); | |
14c44e2e | 1133 | __STRING_INLINE char * |
a784e502 | 1134 | __strpbrk_c3 (const char *__s, int __accept1, int __accept2, int __accept3) |
14c44e2e UD |
1135 | { |
1136 | /* Please note that __accept1 to __accept3 never can be '\0'. */ | |
1137 | while (*__s != '\0' && *__s != __accept1 && *__s != __accept2 | |
1138 | && *__s != __accept3) | |
1139 | ++__s; | |
d2537a47 | 1140 | return *__s == '\0' ? NULL : (char *) (size_t) __s; |
14c44e2e | 1141 | } |
9a0a462c UD |
1142 | #endif |
1143 | ||
1144 | ||
e8e24320 UD |
1145 | /* Find the first occurrence of NEEDLE in HAYSTACK. Newer gcc versions |
1146 | do this itself. */ | |
1147 | #if !defined _HAVE_STRING_ARCH_strstr && !__GNUC_PREREQ (2, 97) | |
9a0a462c | 1148 | # define strstr(haystack, needle) \ |
dfd2257a | 1149 | (__extension__ (__builtin_constant_p (needle) && __string2_1bptr_p (needle) \ |
a784e502 | 1150 | ? (((const char *) (needle))[0] == '\0' \ |
d2537a47 | 1151 | ? (char *) (size_t) (haystack) \ |
a784e502 | 1152 | : (((const char *) (needle))[1] == '\0' \ |
af6f3906 | 1153 | ? strchr (haystack, \ |
a784e502 | 1154 | ((const char *) (needle))[0]) \ |
9a0a462c UD |
1155 | : strstr (haystack, needle))) \ |
1156 | : strstr (haystack, needle))) | |
1157 | #endif | |
1158 | ||
1159 | ||
61423e13 UD |
1160 | #if !defined _HAVE_STRING_ARCH_strtok_r || defined _FORCE_INLINES |
1161 | # ifndef _HAVE_STRING_ARCH_strtok_r | |
1162 | # define __strtok_r(s, sep, nextp) \ | |
6973fc01 | 1163 | (__extension__ (__builtin_constant_p (sep) && __string2_1bptr_p (sep) \ |
a784e502 UD |
1164 | && ((const char *) (sep))[0] != '\0' \ |
1165 | && ((const char *) (sep))[1] == '\0' \ | |
1166 | ? __strtok_r_1c (s, ((const char *) (sep))[0], nextp) \ | |
7551a1e5 | 1167 | : __strtok_r (s, sep, nextp))) |
61423e13 | 1168 | # endif |
6973fc01 UD |
1169 | |
1170 | __STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp); | |
1171 | __STRING_INLINE char * | |
1172 | __strtok_r_1c (char *__s, char __sep, char **__nextp) | |
1173 | { | |
1174 | char *__result; | |
1175 | if (__s == NULL) | |
1176 | __s = *__nextp; | |
1177 | while (*__s == __sep) | |
1178 | ++__s; | |
61423e13 UD |
1179 | __result = NULL; |
1180 | if (*__s != '\0') | |
6973fc01 | 1181 | { |
61423e13 | 1182 | __result = __s++; |
29215bbd UD |
1183 | while (*__s != '\0') |
1184 | if (*__s++ == __sep) | |
1185 | { | |
1186 | __s[-1] = '\0'; | |
1187 | break; | |
1188 | } | |
6973fc01 | 1189 | } |
ebca8f73 | 1190 | *__nextp = __s; |
6973fc01 UD |
1191 | return __result; |
1192 | } | |
31161268 | 1193 | # if defined __USE_POSIX || defined __USE_MISC |
61423e13 | 1194 | # define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp) |
6973fc01 UD |
1195 | # endif |
1196 | #endif | |
1197 | ||
1198 | ||
61423e13 UD |
1199 | #if !defined _HAVE_STRING_ARCH_strsep || defined _FORCE_INLINES |
1200 | # ifndef _HAVE_STRING_ARCH_strsep | |
b61345a1 | 1201 | |
a784e502 | 1202 | extern char *__strsep_g (char **__stringp, const char *__delim); |
61423e13 | 1203 | # define __strsep(s, reject) \ |
36ab45e1 UD |
1204 | __extension__ \ |
1205 | ({ char __r0, __r1, __r2; \ | |
1206 | (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \ | |
a784e502 UD |
1207 | && (__r0 = ((const char *) (reject))[0], \ |
1208 | ((const char *) (reject))[0] != '\0') \ | |
1209 | ? ((__r1 = ((const char *) (reject))[1], \ | |
1210 | ((const char *) (reject))[1] == '\0') \ | |
36ab45e1 | 1211 | ? __strsep_1c (s, __r0) \ |
a784e502 | 1212 | : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \ |
36ab45e1 | 1213 | ? __strsep_2c (s, __r0, __r1) \ |
a784e502 | 1214 | : (((const char *) (reject))[3] == '\0' \ |
36ab45e1 | 1215 | ? __strsep_3c (s, __r0, __r1, __r2) \ |
b61345a1 UD |
1216 | : __strsep_g (s, reject)))) \ |
1217 | : __strsep_g (s, reject)); }) | |
61423e13 | 1218 | # endif |
61eb22d3 UD |
1219 | |
1220 | __STRING_INLINE char *__strsep_1c (char **__s, char __reject); | |
1221 | __STRING_INLINE char * | |
1222 | __strsep_1c (char **__s, char __reject) | |
1223 | { | |
650425ce | 1224 | register char *__retval = *__s; |
61423e13 | 1225 | if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL) |
61eb22d3 | 1226 | *(*__s)++ = '\0'; |
14c44e2e UD |
1227 | return __retval; |
1228 | } | |
1229 | ||
1230 | __STRING_INLINE char *__strsep_2c (char **__s, char __reject1, char __reject2); | |
1231 | __STRING_INLINE char * | |
1232 | __strsep_2c (char **__s, char __reject1, char __reject2) | |
1233 | { | |
1234 | register char *__retval = *__s; | |
61423e13 | 1235 | if (__retval != NULL) |
14c44e2e UD |
1236 | { |
1237 | register char *__cp = __retval; | |
61423e13 | 1238 | while (1) |
14c44e2e | 1239 | { |
61423e13 UD |
1240 | if (*__cp == '\0') |
1241 | { | |
1242 | __cp = NULL; | |
1243 | break; | |
1244 | } | |
1245 | if (*__cp == __reject1 || *__cp == __reject2) | |
1246 | { | |
1247 | *__cp++ = '\0'; | |
1248 | break; | |
1249 | } | |
1250 | ++__cp; | |
14c44e2e | 1251 | } |
61423e13 | 1252 | *__s = __cp; |
14c44e2e UD |
1253 | } |
1254 | return __retval; | |
1255 | } | |
1256 | ||
1257 | __STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2, | |
1258 | char __reject3); | |
1259 | __STRING_INLINE char * | |
1260 | __strsep_3c (char **__s, char __reject1, char __reject2, char __reject3) | |
1261 | { | |
1262 | register char *__retval = *__s; | |
61423e13 | 1263 | if (__retval != NULL) |
14c44e2e UD |
1264 | { |
1265 | register char *__cp = __retval; | |
61423e13 | 1266 | while (1) |
14c44e2e | 1267 | { |
61423e13 UD |
1268 | if (*__cp == '\0') |
1269 | { | |
1270 | __cp = NULL; | |
1271 | break; | |
1272 | } | |
1273 | if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3) | |
1274 | { | |
1275 | *__cp++ = '\0'; | |
1276 | break; | |
1277 | } | |
1278 | ++__cp; | |
14c44e2e | 1279 | } |
61423e13 | 1280 | *__s = __cp; |
14c44e2e | 1281 | } |
650425ce | 1282 | return __retval; |
61eb22d3 | 1283 | } |
31161268 | 1284 | # ifdef __USE_BSD |
61423e13 | 1285 | # define strsep(s, reject) __strsep (s, reject) |
31161268 UD |
1286 | # endif |
1287 | #endif | |
1288 | ||
7ef90c15 | 1289 | /* We need the memory allocation functions for inline strdup(). |
d2537a47 | 1290 | Referring to stdlib.h (even minimally) is not allowed |
4a582094 | 1291 | in any of the tight standards compliant modes. */ |
6e2cc2c1 | 1292 | #ifdef __USE_MISC |
31161268 | 1293 | |
4a582094 UD |
1294 | # if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup |
1295 | # define __need_malloc_and_calloc | |
1296 | # include <stdlib.h> | |
1297 | # endif | |
7ef90c15 | 1298 | |
4a582094 | 1299 | # ifndef _HAVE_STRING_ARCH_strdup |
31161268 | 1300 | |
a784e502 | 1301 | extern char *__strdup (const char *__string) __THROW __attribute_malloc__; |
4a582094 | 1302 | # define __strdup(s) \ |
7551a1e5 | 1303 | (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ |
a784e502 | 1304 | ? (((const char *) (s))[0] == '\0' \ |
a83b5649 | 1305 | ? (char *) calloc ((size_t) 1, (size_t) 1) \ |
7551a1e5 UD |
1306 | : ({ size_t __len = strlen (s) + 1; \ |
1307 | char *__retval = (char *) malloc (__len); \ | |
1308 | if (__retval != NULL) \ | |
1309 | __retval = (char *) memcpy (__retval, s, __len); \ | |
1310 | __retval; })) \ | |
1311 | : __strdup (s))) | |
31161268 | 1312 | |
4a582094 UD |
1313 | # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
1314 | # define strdup(s) __strdup (s) | |
1315 | # endif | |
61eb22d3 | 1316 | # endif |
61eb22d3 | 1317 | |
4a582094 | 1318 | # ifndef _HAVE_STRING_ARCH_strndup |
7551a1e5 | 1319 | |
a784e502 | 1320 | extern char *__strndup (const char *__string, size_t __n) |
160016c9 | 1321 | __THROW __attribute_malloc__; |
4a582094 | 1322 | # define __strndup(s, n) \ |
7551a1e5 | 1323 | (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \ |
a784e502 | 1324 | ? (((const char *) (s))[0] == '\0' \ |
a83b5649 | 1325 | ? (char *) calloc ((size_t) 1, (size_t) 1) \ |
7551a1e5 UD |
1326 | : ({ size_t __len = strlen (s) + 1; \ |
1327 | size_t __n = (n); \ | |
1328 | char *__retval; \ | |
1329 | if (__n < __len) \ | |
fb4fb542 | 1330 | __len = __n + 1; \ |
7551a1e5 UD |
1331 | __retval = (char *) malloc (__len); \ |
1332 | if (__retval != NULL) \ | |
1333 | { \ | |
1334 | __retval[__len - 1] = '\0'; \ | |
1335 | __retval = (char *) memcpy (__retval, s, \ | |
1336 | __len - 1); \ | |
1337 | } \ | |
1338 | __retval; })) \ | |
61423e13 | 1339 | : __strndup (s, n))) |
7551a1e5 | 1340 | |
3356ac25 | 1341 | # ifdef __USE_GNU |
61423e13 | 1342 | # define strndup(s, n) __strndup (s, n) |
4a582094 | 1343 | # endif |
7551a1e5 | 1344 | # endif |
7551a1e5 | 1345 | |
4a582094 | 1346 | #endif /* Use misc. or use GNU. */ |
7551a1e5 | 1347 | |
9bbd7837 UD |
1348 | #ifndef _FORCE_INLINES |
1349 | # undef __STRING_INLINE | |
1350 | #endif | |
9a0a462c | 1351 | |
61eb22d3 | 1352 | #endif /* No string inlines. */ |