Use x86_64 fpu/bits/fenv.h for i386 and x86_64
[glibc.git] / string / bits / string2.h
blobbbf05a3df620d655d187d79f91c25d0daa36d967
1 /* Machine-independant string function optimizations.
2 Copyright (C) 1997-2004, 2007, 2008, 2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _STRING_H
21 # error "Never use <bits/string2.h> directly; include <string.h> instead."
22 #endif
24 #if !defined __NO_STRING_INLINES && !defined __BOUNDED_POINTERS__
26 /* Unlike the definitions in the header <bits/string.h> the
27 definitions contained here are not optimized down to assembler
28 level. Those optimizations are not always a good idea since this
29 means the code size increases a lot. Instead the definitions here
30 optimize some functions in a way which do not dramatically
31 increase the code size and which do not use assembler. The main
32 trick is to use GCC's `__builtin_constant_p' function.
34 Every function XXX which has a defined version in
35 <bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX
36 to make sure we don't get redefinitions.
38 We must use here macros instead of inline functions since the
39 trick won't work with the latter. */
41 #ifndef __STRING_INLINE
42 # ifdef __cplusplus
43 # define __STRING_INLINE inline
44 # else
45 # define __STRING_INLINE __extern_inline
46 # endif
47 #endif
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>
54 # if __BYTE_ORDER == __LITTLE_ENDIAN
55 # define __STRING2_SMALL_GET16(src, idx) \
56 (((const unsigned char *) (const char *) (src))[idx + 1] << 8 \
57 | ((const unsigned char *) (const char *) (src))[idx])
58 # define __STRING2_SMALL_GET32(src, idx) \
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])
63 # else
64 # define __STRING2_SMALL_GET16(src, idx) \
65 (((const unsigned char *) (const char *) (src))[idx] << 8 \
66 | ((const unsigned char *) (const char *) (src))[idx + 1])
67 # define __STRING2_SMALL_GET32(src, idx) \
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])
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) \
77 typedef struct { unsigned char __arr[N]; } \
78 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
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
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) \
93 ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
95 /* Set N bytes of S to C. */
96 #if !defined _HAVE_STRING_ARCH_memset
97 # if !__GNUC_PREREQ (3, 0)
98 # if _STRING_ARCH_unaligned
99 # define memset(s, c, n) \
100 (__extension__ (__builtin_constant_p (n) && (n) <= 16 \
101 ? ((n) == 1 \
102 ? __memset_1 (s, c) \
103 : __memset_gc (s, c, n)) \
104 : (__builtin_constant_p (c) && (c) == '\0' \
105 ? ({ void *__s = (s); __bzero (__s, n); __s; }) \
106 : memset (s, c, n))))
108 # define __memset_1(s, c) ({ void *__s = (s); \
109 *((__uint8_t *) __s) = (__uint8_t) c; __s; })
111 # define __memset_gc(s, c, n) \
112 ({ void *__s = (s); \
113 union { \
114 unsigned int __ui; \
115 unsigned short int __usi; \
116 unsigned char __uc; \
117 } *__u = __s; \
118 __uint8_t __c = (__uint8_t) (c); \
120 /* This `switch' statement will be removed at compile-time. */ \
121 switch ((unsigned int) (n)) \
123 case 15: \
124 __u->__ui = __c * 0x01010101; \
125 __u = __extension__ ((void *) __u + 4); \
126 case 11: \
127 __u->__ui = __c * 0x01010101; \
128 __u = __extension__ ((void *) __u + 4); \
129 case 7: \
130 __u->__ui = __c * 0x01010101; \
131 __u = __extension__ ((void *) __u + 4); \
132 case 3: \
133 __u->__usi = (unsigned short int) __c * 0x0101; \
134 __u = __extension__ ((void *) __u + 2); \
135 __u->__uc = (unsigned char) __c; \
136 break; \
138 case 14: \
139 __u->__ui = __c * 0x01010101; \
140 __u = __extension__ ((void *) __u + 4); \
141 case 10: \
142 __u->__ui = __c * 0x01010101; \
143 __u = __extension__ ((void *) __u + 4); \
144 case 6: \
145 __u->__ui = __c * 0x01010101; \
146 __u = __extension__ ((void *) __u + 4); \
147 case 2: \
148 __u->__usi = (unsigned short int) __c * 0x0101; \
149 break; \
151 case 13: \
152 __u->__ui = __c * 0x01010101; \
153 __u = __extension__ ((void *) __u + 4); \
154 case 9: \
155 __u->__ui = __c * 0x01010101; \
156 __u = __extension__ ((void *) __u + 4); \
157 case 5: \
158 __u->__ui = __c * 0x01010101; \
159 __u = __extension__ ((void *) __u + 4); \
160 case 1: \
161 __u->__uc = (unsigned char) __c; \
162 break; \
164 case 16: \
165 __u->__ui = __c * 0x01010101; \
166 __u = __extension__ ((void *) __u + 4); \
167 case 12: \
168 __u->__ui = __c * 0x01010101; \
169 __u = __extension__ ((void *) __u + 4); \
170 case 8: \
171 __u->__ui = __c * 0x01010101; \
172 __u = __extension__ ((void *) __u + 4); \
173 case 4: \
174 __u->__ui = __c * 0x01010101; \
175 case 0: \
176 break; \
179 __s; })
180 # else
181 # define memset(s, c, n) \
182 (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
183 ? ({ void *__s = (s); __bzero (__s, n); __s; }) \
184 : memset (s, c, n)))
185 # endif
186 # endif
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. */
193 # if __GNUC_PREREQ (2, 91)
194 # define __bzero(s, n) __builtin_memset (s, '\0', n)
195 # endif
197 #endif
200 /* Copy N bytes from SRC to DEST, returning pointer to byte following the
201 last copied. */
202 #ifdef __USE_GNU
203 # if !defined _HAVE_STRING_ARCH_mempcpy || defined _FORCE_INLINES
204 # ifndef _HAVE_STRING_ARCH_mempcpy
205 # if __GNUC_PREREQ (3, 4)
206 # define __mempcpy(dest, src, n) __builtin_mempcpy (dest, src, n)
207 # elif __GNUC_PREREQ (3, 0)
208 # define __mempcpy(dest, src, n) \
209 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
210 && __string2_1bptr_p (src) && n <= 8 \
211 ? __builtin_memcpy (dest, src, n) + (n) \
212 : __mempcpy (dest, src, n)))
213 # else
214 # define __mempcpy(dest, src, n) \
215 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
216 && __string2_1bptr_p (src) && n <= 8 \
217 ? __mempcpy_small (dest, __mempcpy_args (src), n) \
218 : __mempcpy (dest, src, n)))
219 # endif
220 /* In glibc we use this function frequently but for namespace reasons
221 we have to use the name `__mempcpy'. */
222 # define mempcpy(dest, src, n) __mempcpy (dest, src, n)
223 # endif
225 # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES
226 # if _STRING_ARCH_unaligned
227 # ifndef _FORCE_INLINES
228 # define __mempcpy_args(src) \
229 ((const char *) (src))[0], ((const char *) (src))[2], \
230 ((const char *) (src))[4], ((const char *) (src))[6], \
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)
235 # endif
236 __STRING_INLINE void *__mempcpy_small (void *, char, char, char, char,
237 __uint16_t, __uint16_t, __uint32_t,
238 __uint32_t, size_t);
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)
246 union {
247 __uint32_t __ui;
248 __uint16_t __usi;
249 unsigned char __uc;
250 unsigned char __c;
251 } *__u = __dest1;
252 switch ((unsigned int) __srclen)
254 case 1:
255 __u->__c = __src0_1;
256 __u = __extension__ ((void *) __u + 1);
257 break;
258 case 2:
259 __u->__usi = __src0_2;
260 __u = __extension__ ((void *) __u + 2);
261 break;
262 case 3:
263 __u->__usi = __src0_2;
264 __u = __extension__ ((void *) __u + 2);
265 __u->__c = __src2_1;
266 __u = __extension__ ((void *) __u + 1);
267 break;
268 case 4:
269 __u->__ui = __src0_4;
270 __u = __extension__ ((void *) __u + 4);
271 break;
272 case 5:
273 __u->__ui = __src0_4;
274 __u = __extension__ ((void *) __u + 4);
275 __u->__c = __src4_1;
276 __u = __extension__ ((void *) __u + 1);
277 break;
278 case 6:
279 __u->__ui = __src0_4;
280 __u = __extension__ ((void *) __u + 4);
281 __u->__usi = __src4_2;
282 __u = __extension__ ((void *) __u + 2);
283 break;
284 case 7:
285 __u->__ui = __src0_4;
286 __u = __extension__ ((void *) __u + 4);
287 __u->__usi = __src4_2;
288 __u = __extension__ ((void *) __u + 2);
289 __u->__c = __src6_1;
290 __u = __extension__ ((void *) __u + 1);
291 break;
292 case 8:
293 __u->__ui = __src0_4;
294 __u = __extension__ ((void *) __u + 4);
295 __u->__ui = __src4_4;
296 __u = __extension__ ((void *) __u + 4);
297 break;
299 return (void *) __u;
301 # else
302 # ifndef _FORCE_INLINES
303 # define __mempcpy_args(src) \
304 ((const char *) (src))[0], \
305 __extension__ ((__STRING2_COPY_ARR2) \
306 { { ((const char *) (src))[0], ((const char *) (src))[1] } }), \
307 __extension__ ((__STRING2_COPY_ARR3) \
308 { { ((const char *) (src))[0], ((const char *) (src))[1], \
309 ((const char *) (src))[2] } }), \
310 __extension__ ((__STRING2_COPY_ARR4) \
311 { { ((const char *) (src))[0], ((const char *) (src))[1], \
312 ((const char *) (src))[2], ((const char *) (src))[3] } }), \
313 __extension__ ((__STRING2_COPY_ARR5) \
314 { { ((const char *) (src))[0], ((const char *) (src))[1], \
315 ((const char *) (src))[2], ((const char *) (src))[3], \
316 ((const char *) (src))[4] } }), \
317 __extension__ ((__STRING2_COPY_ARR6) \
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] } }), \
321 __extension__ ((__STRING2_COPY_ARR7) \
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] } }), \
326 __extension__ ((__STRING2_COPY_ARR8) \
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] } })
331 # endif
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);
339 __STRING_INLINE void *
340 __mempcpy_small (void *__dest, char __src1,
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)
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;
356 switch ((unsigned int) __srclen)
358 case 1:
359 __u->__c = __src1;
360 break;
361 case 2:
362 __extension__ __u->__sca2 = __src2;
363 break;
364 case 3:
365 __extension__ __u->__sca3 = __src3;
366 break;
367 case 4:
368 __extension__ __u->__sca4 = __src4;
369 break;
370 case 5:
371 __extension__ __u->__sca5 = __src5;
372 break;
373 case 6:
374 __extension__ __u->__sca6 = __src6;
375 break;
376 case 7:
377 __extension__ __u->__sca7 = __src7;
378 break;
379 case 8:
380 __extension__ __u->__sca8 = __src8;
381 break;
383 return __extension__ ((void *) __u + __srclen);
385 # endif
386 # endif
387 # endif
388 #endif
391 /* Return pointer to C in S. */
392 #ifndef _HAVE_STRING_ARCH_strchr
393 extern void *__rawmemchr (const void *__s, int __c);
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) \
402 (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
403 ? (char *) __rawmemchr (s, c) \
404 : strchr (s, c)))
405 # endif
406 #endif
409 /* Copy SRC to DEST. */
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)
413 # define strcpy(dest, src) \
414 (__extension__ (__builtin_constant_p (src) \
415 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
416 ? __strcpy_small (dest, __strcpy_args (src), \
417 strlen (src) + 1) \
418 : (char *) memcpy (dest, src, strlen (src) + 1)) \
419 : strcpy (dest, src)))
420 # endif
422 # if _STRING_ARCH_unaligned
423 # ifndef _FORCE_INLINES
424 # define __strcpy_args(src) \
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)
429 # endif
430 __STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
431 __uint32_t, __uint32_t, size_t);
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)
438 union {
439 __uint32_t __ui;
440 __uint16_t __usi;
441 unsigned char __uc;
442 } *__u = (void *) __dest;
443 switch ((unsigned int) __srclen)
445 case 1:
446 __u->__uc = '\0';
447 break;
448 case 2:
449 __u->__usi = __src0_2;
450 break;
451 case 3:
452 __u->__usi = __src0_2;
453 __u = __extension__ ((void *) __u + 2);
454 __u->__uc = '\0';
455 break;
456 case 4:
457 __u->__ui = __src0_4;
458 break;
459 case 5:
460 __u->__ui = __src0_4;
461 __u = __extension__ ((void *) __u + 4);
462 __u->__uc = '\0';
463 break;
464 case 6:
465 __u->__ui = __src0_4;
466 __u = __extension__ ((void *) __u + 4);
467 __u->__usi = __src4_2;
468 break;
469 case 7:
470 __u->__ui = __src0_4;
471 __u = __extension__ ((void *) __u + 4);
472 __u->__usi = __src4_2;
473 __u = __extension__ ((void *) __u + 2);
474 __u->__uc = '\0';
475 break;
476 case 8:
477 __u->__ui = __src0_4;
478 __u = __extension__ ((void *) __u + 4);
479 __u->__ui = __src4_4;
480 break;
482 return __dest;
484 # else
485 # ifndef _FORCE_INLINES
486 # define __strcpy_args(src) \
487 __extension__ ((__STRING2_COPY_ARR2) \
488 { { ((const char *) (src))[0], '\0' } }), \
489 __extension__ ((__STRING2_COPY_ARR3) \
490 { { ((const char *) (src))[0], ((const char *) (src))[1], \
491 '\0' } }), \
492 __extension__ ((__STRING2_COPY_ARR4) \
493 { { ((const char *) (src))[0], ((const char *) (src))[1], \
494 ((const char *) (src))[2], '\0' } }), \
495 __extension__ ((__STRING2_COPY_ARR5) \
496 { { ((const char *) (src))[0], ((const char *) (src))[1], \
497 ((const char *) (src))[2], ((const char *) (src))[3], \
498 '\0' } }), \
499 __extension__ ((__STRING2_COPY_ARR6) \
500 { { ((const char *) (src))[0], ((const char *) (src))[1], \
501 ((const char *) (src))[2], ((const char *) (src))[3], \
502 ((const char *) (src))[4], '\0' } }), \
503 __extension__ ((__STRING2_COPY_ARR7) \
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], \
507 '\0' } }), \
508 __extension__ ((__STRING2_COPY_ARR8) \
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' } })
513 # endif
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);
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)
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;
537 } *__u = (void *) __dest;
538 switch ((unsigned int) __srclen)
540 case 1:
541 __u->__c = '\0';
542 break;
543 case 2:
544 __extension__ __u->__sca2 = __src2;
545 break;
546 case 3:
547 __extension__ __u->__sca3 = __src3;
548 break;
549 case 4:
550 __extension__ __u->__sca4 = __src4;
551 break;
552 case 5:
553 __extension__ __u->__sca5 = __src5;
554 break;
555 case 6:
556 __extension__ __u->__sca6 = __src6;
557 break;
558 case 7:
559 __extension__ __u->__sca7 = __src7;
560 break;
561 case 8:
562 __extension__ __u->__sca8 = __src8;
563 break;
565 return __dest;
567 # endif
568 #endif
571 /* Copy SRC to DEST, returning pointer to final NUL byte. */
572 #ifdef __USE_GNU
573 # if !defined _HAVE_STRING_ARCH_stpcpy || defined _FORCE_INLINES
574 # ifndef _HAVE_STRING_ARCH_stpcpy
575 # if __GNUC_PREREQ (3, 4)
576 # define __stpcpy(dest, src) __builtin_stpcpy (dest, src)
577 # elif __GNUC_PREREQ (3, 0)
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) \
587 (__extension__ (__builtin_constant_p (src) \
588 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
589 ? __stpcpy_small (dest, __stpcpy_args (src), \
590 strlen (src) + 1) \
591 : ((char *) (__mempcpy) (dest, src, strlen (src) + 1) \
592 - 1)) \
593 : __stpcpy (dest, src)))
594 # endif
595 /* In glibc we use this function frequently but for namespace reasons
596 we have to use the name `__stpcpy'. */
597 # define stpcpy(dest, src) __stpcpy (dest, src)
598 # endif
600 # if !__GNUC_PREREQ (3, 0) || defined _FORCE_INLINES
601 # if _STRING_ARCH_unaligned
602 # ifndef _FORCE_INLINES
603 # define __stpcpy_args(src) \
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)
608 # endif
609 __STRING_INLINE char *__stpcpy_small (char *, __uint16_t, __uint16_t,
610 __uint32_t, __uint32_t, size_t);
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)
617 union {
618 unsigned int __ui;
619 unsigned short int __usi;
620 unsigned char __uc;
621 char __c;
622 } *__u = (void *) __dest;
623 switch ((unsigned int) __srclen)
625 case 1:
626 __u->__uc = '\0';
627 break;
628 case 2:
629 __u->__usi = __src0_2;
630 __u = __extension__ ((void *) __u + 1);
631 break;
632 case 3:
633 __u->__usi = __src0_2;
634 __u = __extension__ ((void *) __u + 2);
635 __u->__uc = '\0';
636 break;
637 case 4:
638 __u->__ui = __src0_4;
639 __u = __extension__ ((void *) __u + 3);
640 break;
641 case 5:
642 __u->__ui = __src0_4;
643 __u = __extension__ ((void *) __u + 4);
644 __u->__uc = '\0';
645 break;
646 case 6:
647 __u->__ui = __src0_4;
648 __u = __extension__ ((void *) __u + 4);
649 __u->__usi = __src4_2;
650 __u = __extension__ ((void *) __u + 1);
651 break;
652 case 7:
653 __u->__ui = __src0_4;
654 __u = __extension__ ((void *) __u + 4);
655 __u->__usi = __src4_2;
656 __u = __extension__ ((void *) __u + 2);
657 __u->__uc = '\0';
658 break;
659 case 8:
660 __u->__ui = __src0_4;
661 __u = __extension__ ((void *) __u + 4);
662 __u->__ui = __src4_4;
663 __u = __extension__ ((void *) __u + 3);
664 break;
666 return &__u->__c;
668 # else
669 # ifndef _FORCE_INLINES
670 # define __stpcpy_args(src) \
671 __extension__ ((__STRING2_COPY_ARR2) \
672 { { ((const char *) (src))[0], '\0' } }), \
673 __extension__ ((__STRING2_COPY_ARR3) \
674 { { ((const char *) (src))[0], ((const char *) (src))[1], \
675 '\0' } }), \
676 __extension__ ((__STRING2_COPY_ARR4) \
677 { { ((const char *) (src))[0], ((const char *) (src))[1], \
678 ((const char *) (src))[2], '\0' } }), \
679 __extension__ ((__STRING2_COPY_ARR5) \
680 { { ((const char *) (src))[0], ((const char *) (src))[1], \
681 ((const char *) (src))[2], ((const char *) (src))[3], \
682 '\0' } }), \
683 __extension__ ((__STRING2_COPY_ARR6) \
684 { { ((const char *) (src))[0], ((const char *) (src))[1], \
685 ((const char *) (src))[2], ((const char *) (src))[3], \
686 ((const char *) (src))[4], '\0' } }), \
687 __extension__ ((__STRING2_COPY_ARR7) \
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], \
691 '\0' } }), \
692 __extension__ ((__STRING2_COPY_ARR8) \
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' } })
697 # endif
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);
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)
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;
721 } *__u = (void *) __dest;
722 switch ((unsigned int) __srclen)
724 case 1:
725 __u->__c = '\0';
726 break;
727 case 2:
728 __extension__ __u->__sca2 = __src2;
729 break;
730 case 3:
731 __extension__ __u->__sca3 = __src3;
732 break;
733 case 4:
734 __extension__ __u->__sca4 = __src4;
735 break;
736 case 5:
737 __extension__ __u->__sca5 = __src5;
738 break;
739 case 6:
740 __extension__ __u->__sca6 = __src6;
741 break;
742 case 7:
743 __extension__ __u->__sca7 = __src7;
744 break;
745 case 8:
746 __extension__ __u->__sca8 = __src8;
747 break;
749 return __dest + __srclen - 1;
751 # endif
752 # endif
753 # endif
754 #endif
757 /* Copy no more than N characters of SRC to DEST. */
758 #ifndef _HAVE_STRING_ARCH_strncpy
759 # if __GNUC_PREREQ (3, 2)
760 # define strncpy(dest, src, n) __builtin_strncpy (dest, src, n)
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
772 /* Append no more than N characters from SRC onto DEST. */
773 #ifndef _HAVE_STRING_ARCH_strncat
774 # ifdef _USE_STRING_ARCH_strchr
775 # define strncat(dest, src, n) \
776 (__extension__ ({ char *__dest = (dest); \
777 __builtin_constant_p (src) && __builtin_constant_p (n) \
778 ? (strlen (src) < ((size_t) (n)) \
779 ? strcat (__dest, src) \
780 : (*((char *) __mempcpy (strchr (__dest, '\0'), \
781 src, n)) = '\0', __dest)) \
782 : strncat (dest, src, n); }))
783 # elif __GNUC_PREREQ (3, 2)
784 # define strncat(dest, src, n) __builtin_strncat (dest, src, n)
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
796 /* Compare characters of S1 and S2. */
797 #ifndef _HAVE_STRING_ARCH_strcmp
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) \
820 __extension__ \
821 ({ size_t __s1_len, __s2_len; \
822 (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
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)) \
826 ? memcmp ((const char *) (s1), (const char *) (s2), \
827 (__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \
828 : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
829 && (__s1_len = strlen (s1), __s1_len < 4) \
830 ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
831 ? __strcmp_cc (s1, s2, __s1_len) \
832 : __strcmp_cg (s1, s2, __s1_len)) \
833 : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
834 && (__s2_len = strlen (s2), __s2_len < 4) \
835 ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
836 ? __strcmp_cc (s1, s2, __s2_len) \
837 : __strcmp_gc (s1, s2, __s2_len)) \
838 : strcmp (s1, s2)))); })
839 # endif
841 # define __strcmp_cc(s1, s2, l) \
842 (__extension__ ({ register int __result = \
843 (((const unsigned char *) (const char *) (s1))[0] \
844 - ((const unsigned char *) (const char *)(s2))[0]); \
845 if (l > 0 && __result == 0) \
847 __result = (((const unsigned char *) \
848 (const char *) (s1))[1] \
849 - ((const unsigned char *) \
850 (const char *) (s2))[1]); \
851 if (l > 1 && __result == 0) \
853 __result = \
854 (((const unsigned char *) \
855 (const char *) (s1))[2] \
856 - ((const unsigned char *) \
857 (const char *) (s2))[2]); \
858 if (l > 2 && __result == 0) \
859 __result = \
860 (((const unsigned char *) \
861 (const char *) (s1))[3] \
862 - ((const unsigned char *) \
863 (const char *) (s2))[3]); \
866 __result; }))
868 # define __strcmp_cg(s1, s2, l1) \
869 (__extension__ ({ const unsigned char *__s2 = \
870 (const unsigned char *) (const char *) (s2); \
871 register int __result = \
872 (((const unsigned char *) (const char *) (s1))[0] \
873 - __s2[0]); \
874 if (l1 > 0 && __result == 0) \
876 __result = (((const unsigned char *) \
877 (const char *) (s1))[1] - __s2[1]); \
878 if (l1 > 1 && __result == 0) \
880 __result = (((const unsigned char *) \
881 (const char *) (s1))[2] - __s2[2]); \
882 if (l1 > 2 && __result == 0) \
883 __result = (((const unsigned char *) \
884 (const char *) (s1))[3] \
885 - __s2[3]); \
888 __result; }))
890 # define __strcmp_gc(s1, s2, l2) \
891 (__extension__ ({ const unsigned char *__s1 = \
892 (const unsigned char *) (const char *) (s1); \
893 register int __result = \
894 __s1[0] - ((const unsigned char *) \
895 (const char *) (s2))[0]; \
896 if (l2 > 0 && __result == 0) \
898 __result = (__s1[1] \
899 - ((const unsigned char *) \
900 (const char *) (s2))[1]); \
901 if (l2 > 1 && __result == 0) \
903 __result = \
904 (__s1[2] - ((const unsigned char *) \
905 (const char *) (s2))[2]); \
906 if (l2 > 2 && __result == 0) \
907 __result = \
908 (__s1[3] \
909 - ((const unsigned char *) \
910 (const char *) (s2))[3]); \
913 __result; }))
914 #endif
917 /* Compare N characters of S1 and S2. */
918 #ifndef _HAVE_STRING_ARCH_strncmp
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)))
926 #endif
929 /* Return the length of the initial segment of S which
930 consists entirely of characters not in REJECT. */
931 #if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES
932 # ifndef _HAVE_STRING_ARCH_strcspn
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) \
940 : ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \
941 ? strlen (s) \
942 : ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \
943 ? __strcspn_c1 (s, __r0) \
944 : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \
945 ? __strcspn_c2 (s, __r0, __r1) \
946 : (((const char *) (reject))[3] == '\0' \
947 ? __strcspn_c3 (s, __r0, __r1, __r2) \
948 : __builtin_strcspn (s, reject)))))) \
949 : __builtin_strcspn (s, reject)); })
950 # else
951 # define strcspn(s, reject) \
952 __extension__ \
953 ({ char __r0, __r1, __r2; \
954 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
955 ? ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \
956 ? strlen (s) \
957 : ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \
958 ? __strcspn_c1 (s, __r0) \
959 : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \
960 ? __strcspn_c2 (s, __r0, __r1) \
961 : (((const char *) (reject))[3] == '\0' \
962 ? __strcspn_c3 (s, __r0, __r1, __r2) \
963 : strcspn (s, reject))))) \
964 : strcspn (s, reject)); })
965 # endif
966 # endif
968 __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
969 __STRING_INLINE size_t
970 __strcspn_c1 (const char *__s, int __reject)
972 register size_t __result = 0;
973 while (__s[__result] != '\0' && __s[__result] != __reject)
974 ++__result;
975 return __result;
978 __STRING_INLINE size_t __strcspn_c2 (const char *__s, int __reject1,
979 int __reject2);
980 __STRING_INLINE size_t
981 __strcspn_c2 (const char *__s, int __reject1, int __reject2)
983 register size_t __result = 0;
984 while (__s[__result] != '\0' && __s[__result] != __reject1
985 && __s[__result] != __reject2)
986 ++__result;
987 return __result;
990 __STRING_INLINE size_t __strcspn_c3 (const char *__s, int __reject1,
991 int __reject2, int __reject3);
992 __STRING_INLINE size_t
993 __strcspn_c3 (const char *__s, int __reject1, int __reject2,
994 int __reject3)
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;
1002 #endif
1005 /* Return the length of the initial segment of S which
1006 consists entirely of characters in ACCEPT. */
1007 #if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES
1008 # ifndef _HAVE_STRING_ARCH_strspn
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) \
1016 : ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
1017 ? ((void) (s), (size_t) 0) \
1018 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
1019 ? __strspn_c1 (s, __a0) \
1020 : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
1021 ? __strspn_c2 (s, __a0, __a1) \
1022 : (((const char *) (accept))[3] == '\0' \
1023 ? __strspn_c3 (s, __a0, __a1, __a2) \
1024 : __builtin_strspn (s, accept)))))) \
1025 : __builtin_strspn (s, accept)); })
1026 # else
1027 # define strspn(s, accept) \
1028 __extension__ \
1029 ({ char __a0, __a1, __a2; \
1030 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
1031 ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
1032 ? ((void) (s), (size_t) 0) \
1033 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
1034 ? __strspn_c1 (s, __a0) \
1035 : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
1036 ? __strspn_c2 (s, __a0, __a1) \
1037 : (((const char *) (accept))[3] == '\0' \
1038 ? __strspn_c3 (s, __a0, __a1, __a2) \
1039 : strspn (s, accept))))) \
1040 : strspn (s, accept)); })
1041 # endif
1042 # endif
1044 __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept);
1045 __STRING_INLINE size_t
1046 __strspn_c1 (const char *__s, int __accept)
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;
1055 __STRING_INLINE size_t __strspn_c2 (const char *__s, int __accept1,
1056 int __accept2);
1057 __STRING_INLINE size_t
1058 __strspn_c2 (const char *__s, int __accept1, int __accept2)
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;
1067 __STRING_INLINE size_t __strspn_c3 (const char *__s, int __accept1,
1068 int __accept2, int __accept3);
1069 __STRING_INLINE size_t
1070 __strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3)
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;
1079 #endif
1082 /* Find the first occurrence in S of any character in ACCEPT. */
1083 #if !defined _HAVE_STRING_ARCH_strpbrk || defined _FORCE_INLINES
1084 # ifndef _HAVE_STRING_ARCH_strpbrk
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) \
1092 : ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
1093 ? ((void) (s), (char *) NULL) \
1094 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
1095 ? __builtin_strchr (s, __a0) \
1096 : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
1097 ? __strpbrk_c2 (s, __a0, __a1) \
1098 : (((const char *) (accept))[3] == '\0' \
1099 ? __strpbrk_c3 (s, __a0, __a1, __a2) \
1100 : __builtin_strpbrk (s, accept)))))) \
1101 : __builtin_strpbrk (s, accept)); })
1102 # else
1103 # define strpbrk(s, accept) \
1104 __extension__ \
1105 ({ char __a0, __a1, __a2; \
1106 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
1107 ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
1108 ? ((void) (s), (char *) NULL) \
1109 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
1110 ? strchr (s, __a0) \
1111 : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
1112 ? __strpbrk_c2 (s, __a0, __a1) \
1113 : (((const char *) (accept))[3] == '\0' \
1114 ? __strpbrk_c3 (s, __a0, __a1, __a2) \
1115 : strpbrk (s, accept))))) \
1116 : strpbrk (s, accept)); })
1117 # endif
1118 # endif
1120 __STRING_INLINE char *__strpbrk_c2 (const char *__s, int __accept1,
1121 int __accept2);
1122 __STRING_INLINE char *
1123 __strpbrk_c2 (const char *__s, int __accept1, int __accept2)
1125 /* Please note that __accept1 and __accept2 never can be '\0'. */
1126 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2)
1127 ++__s;
1128 return *__s == '\0' ? NULL : (char *) (size_t) __s;
1131 __STRING_INLINE char *__strpbrk_c3 (const char *__s, int __accept1,
1132 int __accept2, int __accept3);
1133 __STRING_INLINE char *
1134 __strpbrk_c3 (const char *__s, int __accept1, int __accept2, int __accept3)
1136 /* Please note that __accept1 to __accept3 never can be '\0'. */
1137 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2
1138 && *__s != __accept3)
1139 ++__s;
1140 return *__s == '\0' ? NULL : (char *) (size_t) __s;
1142 #endif
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)
1148 # define strstr(haystack, needle) \
1149 (__extension__ (__builtin_constant_p (needle) && __string2_1bptr_p (needle) \
1150 ? (((const char *) (needle))[0] == '\0' \
1151 ? (char *) (size_t) (haystack) \
1152 : (((const char *) (needle))[1] == '\0' \
1153 ? strchr (haystack, \
1154 ((const char *) (needle))[0]) \
1155 : strstr (haystack, needle))) \
1156 : strstr (haystack, needle)))
1157 #endif
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) \
1163 (__extension__ (__builtin_constant_p (sep) && __string2_1bptr_p (sep) \
1164 && ((const char *) (sep))[0] != '\0' \
1165 && ((const char *) (sep))[1] == '\0' \
1166 ? __strtok_r_1c (s, ((const char *) (sep))[0], nextp) \
1167 : __strtok_r (s, sep, nextp)))
1168 # endif
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)
1174 char *__result;
1175 if (__s == NULL)
1176 __s = *__nextp;
1177 while (*__s == __sep)
1178 ++__s;
1179 __result = NULL;
1180 if (*__s != '\0')
1182 __result = __s++;
1183 while (*__s != '\0')
1184 if (*__s++ == __sep)
1186 __s[-1] = '\0';
1187 break;
1190 *__nextp = __s;
1191 return __result;
1193 # if defined __USE_POSIX || defined __USE_MISC
1194 # define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp)
1195 # endif
1196 #endif
1199 #if !defined _HAVE_STRING_ARCH_strsep || defined _FORCE_INLINES
1200 # ifndef _HAVE_STRING_ARCH_strsep
1202 extern char *__strsep_g (char **__stringp, const char *__delim);
1203 # define __strsep(s, reject) \
1204 __extension__ \
1205 ({ char __r0, __r1, __r2; \
1206 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
1207 && (__r0 = ((const char *) (reject))[0], \
1208 ((const char *) (reject))[0] != '\0') \
1209 ? ((__r1 = ((const char *) (reject))[1], \
1210 ((const char *) (reject))[1] == '\0') \
1211 ? __strsep_1c (s, __r0) \
1212 : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \
1213 ? __strsep_2c (s, __r0, __r1) \
1214 : (((const char *) (reject))[3] == '\0' \
1215 ? __strsep_3c (s, __r0, __r1, __r2) \
1216 : __strsep_g (s, reject)))) \
1217 : __strsep_g (s, reject)); })
1218 # endif
1220 __STRING_INLINE char *__strsep_1c (char **__s, char __reject);
1221 __STRING_INLINE char *
1222 __strsep_1c (char **__s, char __reject)
1224 register char *__retval = *__s;
1225 if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL)
1226 *(*__s)++ = '\0';
1227 return __retval;
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)
1234 register char *__retval = *__s;
1235 if (__retval != NULL)
1237 register char *__cp = __retval;
1238 while (1)
1240 if (*__cp == '\0')
1242 __cp = NULL;
1243 break;
1245 if (*__cp == __reject1 || *__cp == __reject2)
1247 *__cp++ = '\0';
1248 break;
1250 ++__cp;
1252 *__s = __cp;
1254 return __retval;
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)
1262 register char *__retval = *__s;
1263 if (__retval != NULL)
1265 register char *__cp = __retval;
1266 while (1)
1268 if (*__cp == '\0')
1270 __cp = NULL;
1271 break;
1273 if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3)
1275 *__cp++ = '\0';
1276 break;
1278 ++__cp;
1280 *__s = __cp;
1282 return __retval;
1284 # ifdef __USE_BSD
1285 # define strsep(s, reject) __strsep (s, reject)
1286 # endif
1287 #endif
1289 /* We need the memory allocation functions for inline strdup().
1290 Referring to stdlib.h (even minimally) is not allowed
1291 in any of the tight standards compliant modes. */
1292 #ifdef __USE_MISC
1294 # if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
1295 # define __need_malloc_and_calloc
1296 # include <stdlib.h>
1297 # endif
1299 # ifndef _HAVE_STRING_ARCH_strdup
1301 extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
1302 # define __strdup(s) \
1303 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1304 ? (((const char *) (s))[0] == '\0' \
1305 ? (char *) calloc ((size_t) 1, (size_t) 1) \
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)))
1313 # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1314 # define strdup(s) __strdup (s)
1315 # endif
1316 # endif
1318 # ifndef _HAVE_STRING_ARCH_strndup
1320 extern char *__strndup (const char *__string, size_t __n)
1321 __THROW __attribute_malloc__;
1322 # define __strndup(s, n) \
1323 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1324 ? (((const char *) (s))[0] == '\0' \
1325 ? (char *) calloc ((size_t) 1, (size_t) 1) \
1326 : ({ size_t __len = strlen (s) + 1; \
1327 size_t __n = (n); \
1328 char *__retval; \
1329 if (__n < __len) \
1330 __len = __n + 1; \
1331 __retval = (char *) malloc (__len); \
1332 if (__retval != NULL) \
1334 __retval[__len - 1] = '\0'; \
1335 __retval = (char *) memcpy (__retval, s, \
1336 __len - 1); \
1338 __retval; })) \
1339 : __strndup (s, n)))
1341 # ifdef __USE_GNU
1342 # define strndup(s, n) __strndup (s, n)
1343 # endif
1344 # endif
1346 #endif /* Use misc. or use GNU. */
1348 #ifndef _FORCE_INLINES
1349 # undef __STRING_INLINE
1350 #endif
1352 #endif /* No string inlines. */