Update.
[glibc.git] / string / bits / string2.h
blob213ab2e516a6627dc833be42e9ad45b004f9309d
1 /* Machine-independant string function optimizations.
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _STRING_H
22 # error "Never use <bits/string2.h> directly; include <string.h> instead."
23 #endif
25 #if !defined __NO_STRING_INLINES && !defined __BOUNDED_POINTERS__
27 /* Unlike the definitions in the header <bits/string.h> the
28 definitions contained here are not optimized down to assembler
29 level. Those optimizations are not always a good idea since this
30 means the code size increases a lot. Instead the definitions here
31 optimize some functions in a way which do not dramatically
32 increase the code size and which do not use assembler. The main
33 trick is to use GNU CC's `__builtin_constant_p' function.
35 Every function XXX which has a defined version in
36 <bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX
37 to make sure we don't get redefinitions.
39 We must use here macros instead of inline functions since the
40 trick won't work with the latter. */
42 #ifndef __STRING_INLINE
43 # ifdef __cplusplus
44 # define __STRING_INLINE inline
45 # else
46 # define __STRING_INLINE extern __inline
47 # endif
48 #endif
50 #if _STRING_ARCH_unaligned
51 /* If we can do unaligned memory accesses we must know the endianess. */
52 # include <endian.h>
53 # include <bits/types.h>
55 # if __BYTE_ORDER == __LITTLE_ENDIAN
56 # define __STRING2_SMALL_GET16(src, idx) \
57 (((__const unsigned char *) (__const char *) (src))[idx + 1] << 8 \
58 | ((__const unsigned char *) (__const char *) (src))[idx])
59 # define __STRING2_SMALL_GET32(src, idx) \
60 (((((__const unsigned char *) (__const char *) (src))[idx + 3] << 8 \
61 | ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
62 | ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
63 | ((__const unsigned char *) (__const char *) (src))[idx])
64 # else
65 # define __STRING2_SMALL_GET16(src, idx) \
66 (((__const unsigned char *) (__const char *) (src))[idx] << 8 \
67 | ((__const unsigned char *) (__const char *) (src))[idx + 1])
68 # define __STRING2_SMALL_GET32(src, idx) \
69 (((((__const unsigned char *) (__const char *) (src))[idx] << 8 \
70 | ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
71 | ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
72 | ((__const unsigned char *) (__const char *) (src))[idx + 3])
73 # endif
74 #else
75 /* These are a few types we need for the optimizations if we cannot
76 use unaligned memory accesses. */
77 # define __STRING2_COPY_TYPE(N) \
78 typedef struct { unsigned char __arr[N]; } \
79 __STRING2_COPY_ARR##N __attribute__ ((packed))
80 __STRING2_COPY_TYPE (2);
81 __STRING2_COPY_TYPE (3);
82 __STRING2_COPY_TYPE (4);
83 __STRING2_COPY_TYPE (5);
84 __STRING2_COPY_TYPE (6);
85 __STRING2_COPY_TYPE (7);
86 __STRING2_COPY_TYPE (8);
87 # undef __STRING2_COPY_TYPE
88 #endif
90 /* Dereferencing a pointer arg to run sizeof on it fails for the void
91 pointer case, so we use this instead.
92 Note that __x is evaluated twice. */
93 #define __string2_1bptr_p(__x) \
94 ((size_t)(const void *)((__x) + 1) - (size_t)(const void *)(__x) == 1)
96 /* Set N bytes of S to C. */
97 #ifndef _HAVE_STRING_ARCH_memset
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
187 /* GCC optimizes memset(s, 0, n) but not bzero(s, n).
188 The optimization is broken before EGCS 1.1. */
189 # if __GNUC_PREREQ (2, 91)
190 # define __bzero(s, n) __builtin_memset (s, '\0', n)
191 # endif
193 #endif
196 /* Copy N bytes from SRC to DEST, returning pointer to byte following the
197 last copied. */
198 #ifdef __USE_GNU
199 # ifndef _HAVE_STRING_ARCH_mempcpy
200 # define __mempcpy(dest, src, n) \
201 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
202 && __string2_1bptr_p (src) && n <= 8 \
203 ? __mempcpy_small (dest, __mempcpy_args (src), n) \
204 : __mempcpy (dest, src, n)))
205 /* In glibc we use this function frequently but for namespace reasons
206 we have to use the name `__mempcpy'. */
207 # define mempcpy(dest, src, n) __mempcpy (dest, src, n)
209 # if _STRING_ARCH_unaligned
210 # define __mempcpy_args(src) \
211 ((__const char *) (src))[0], ((__const char *) (src))[2], \
212 ((__const char *) (src))[4], ((__const char *) (src))[6], \
213 __extension__ __STRING2_SMALL_GET16 (src, 0), \
214 __extension__ __STRING2_SMALL_GET16 (src, 4), \
215 __extension__ __STRING2_SMALL_GET32 (src, 0), \
216 __extension__ __STRING2_SMALL_GET32 (src, 4)
217 __STRING_INLINE void *__mempcpy_small (void *, char, char, char, char,
218 __uint16_t, __uint16_t, __uint32_t,
219 __uint32_t, size_t);
220 __STRING_INLINE void *
221 __mempcpy_small (void *__dest1,
222 char __src0_1, char __src2_1, char __src4_1, char __src6_1,
223 __uint16_t __src0_2, __uint16_t __src4_2,
224 __uint32_t __src0_4, __uint32_t __src4_4,
225 size_t __srclen)
227 union {
228 __uint32_t __ui;
229 __uint16_t __usi;
230 unsigned char __uc;
231 unsigned char __c;
232 } *__u = __dest1;
233 switch ((unsigned int) __srclen)
235 case 1:
236 __u->__c = __src0_1;
237 __u = __extension__ ((void *) __u + 1);
238 break;
239 case 2:
240 __u->__usi = __src0_2;
241 __u = __extension__ ((void *) __u + 2);
242 break;
243 case 3:
244 __u->__usi = __src0_2;
245 __u = __extension__ ((void *) __u + 2);
246 __u->__c = __src2_1;
247 __u = __extension__ ((void *) __u + 1);
248 break;
249 case 4:
250 __u->__ui = __src0_4;
251 __u = __extension__ ((void *) __u + 4);
252 break;
253 case 5:
254 __u->__ui = __src0_4;
255 __u = __extension__ ((void *) __u + 4);
256 __u->__c = __src4_1;
257 __u = __extension__ ((void *) __u + 1);
258 break;
259 case 6:
260 __u->__ui = __src0_4;
261 __u = __extension__ ((void *) __u + 4);
262 __u->__usi = __src4_2;
263 __u = __extension__ ((void *) __u + 2);
264 break;
265 case 7:
266 __u->__ui = __src0_4;
267 __u = __extension__ ((void *) __u + 4);
268 __u->__usi = __src4_2;
269 __u = __extension__ ((void *) __u + 2);
270 __u->__c = __src6_1;
271 __u = __extension__ ((void *) __u + 1);
272 break;
273 case 8:
274 __u->__ui = __src0_4;
275 __u = __extension__ ((void *) __u + 4);
276 __u->__ui = __src4_4;
277 __u = __extension__ ((void *) __u + 4);
278 break;
280 return (void *) __u;
282 # else
283 # define __mempcpy_args(src) \
284 ((__const char *) (src))[0], \
285 __extension__ ((__STRING2_COPY_ARR2) \
286 { { ((__const char *) (src))[0], ((__const char *) (src))[1] } }), \
287 __extension__ ((__STRING2_COPY_ARR3) \
288 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
289 ((__const char *) (src))[2] } }), \
290 __extension__ ((__STRING2_COPY_ARR4) \
291 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
292 ((__const char *) (src))[2], ((__const char *) (src))[3] } }), \
293 __extension__ ((__STRING2_COPY_ARR5) \
294 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
295 ((__const char *) (src))[2], ((__const char *) (src))[3], \
296 ((__const char *) (src))[4] } }), \
297 __extension__ ((__STRING2_COPY_ARR6) \
298 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
299 ((__const char *) (src))[2], ((__const char *) (src))[3], \
300 ((__const char *) (src))[4], ((__const char *) (src))[5] } }), \
301 __extension__ ((__STRING2_COPY_ARR7) \
302 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
303 ((__const char *) (src))[2], ((__const char *) (src))[3], \
304 ((__const char *) (src))[4], ((__const char *) (src))[5], \
305 ((__const char *) (src))[6] } }), \
306 __extension__ ((__STRING2_COPY_ARR8) \
307 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
308 ((__const char *) (src))[2], ((__const char *) (src))[3], \
309 ((__const char *) (src))[4], ((__const char *) (src))[5], \
310 ((__const char *) (src))[6], ((__const char *) (src))[7] } })
311 __STRING_INLINE void *__mempcpy_small (void *, char, __STRING2_COPY_ARR2,
312 __STRING2_COPY_ARR3,
313 __STRING2_COPY_ARR4,
314 __STRING2_COPY_ARR5,
315 __STRING2_COPY_ARR6,
316 __STRING2_COPY_ARR7,
317 __STRING2_COPY_ARR8, size_t);
318 __STRING_INLINE void *
319 __mempcpy_small (void *__dest, char __src1,
320 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
321 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
322 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
323 __STRING2_COPY_ARR8 __src8, size_t __srclen)
325 union {
326 char __c;
327 __STRING2_COPY_ARR2 __sca2;
328 __STRING2_COPY_ARR3 __sca3;
329 __STRING2_COPY_ARR4 __sca4;
330 __STRING2_COPY_ARR5 __sca5;
331 __STRING2_COPY_ARR6 __sca6;
332 __STRING2_COPY_ARR7 __sca7;
333 __STRING2_COPY_ARR8 __sca8;
334 } *__u = __dest;
335 switch ((unsigned int) __srclen)
337 case 1:
338 __u->__c = __src1;
339 break;
340 case 2:
341 __extension__ __u->__sca2 = __src2;
342 break;
343 case 3:
344 __extension__ __u->__sca3 = __src3;
345 break;
346 case 4:
347 __extension__ __u->__sca4 = __src4;
348 break;
349 case 5:
350 __extension__ __u->__sca5 = __src5;
351 break;
352 case 6:
353 __extension__ __u->__sca6 = __src6;
354 break;
355 case 7:
356 __extension__ __u->__sca7 = __src7;
357 break;
358 case 8:
359 __extension__ __u->__sca8 = __src8;
360 break;
362 return __extension__ ((void *) __u + __srclen);
364 # endif
365 # endif
366 #endif
369 /* Return pointer to C in S. */
370 #ifndef _HAVE_STRING_ARCH_strchr
371 extern void *__rawmemchr (const void *__s, int __c);
372 # define strchr(s, c) \
373 (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
374 ? (char *) __rawmemchr (s, c) \
375 : strchr (s, c)))
376 #endif
379 /* Copy SRC to DEST. */
380 #ifndef _HAVE_STRING_ARCH_strcpy
381 # define strcpy(dest, src) \
382 (__extension__ (__builtin_constant_p (src) \
383 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
384 ? __strcpy_small (dest, __strcpy_args (src), \
385 strlen (src) + 1) \
386 : (char *) memcpy (dest, src, strlen (src) + 1)) \
387 : strcpy (dest, src)))
389 # if _STRING_ARCH_unaligned
390 # define __strcpy_args(src) \
391 __extension__ __STRING2_SMALL_GET16 (src, 0), \
392 __extension__ __STRING2_SMALL_GET16 (src, 4), \
393 __extension__ __STRING2_SMALL_GET32 (src, 0), \
394 __extension__ __STRING2_SMALL_GET32 (src, 4)
395 __STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
396 __uint32_t, __uint32_t, size_t);
397 __STRING_INLINE char *
398 __strcpy_small (char *__dest,
399 __uint16_t __src0_2, __uint16_t __src4_2,
400 __uint32_t __src0_4, __uint32_t __src4_4,
401 size_t __srclen)
403 union {
404 __uint32_t __ui;
405 __uint16_t __usi;
406 unsigned char __uc;
407 } *__u = (void *) __dest;
408 switch ((unsigned int) __srclen)
410 case 1:
411 __u->__uc = '\0';
412 break;
413 case 2:
414 __u->__usi = __src0_2;
415 break;
416 case 3:
417 __u->__usi = __src0_2;
418 __u = __extension__ ((void *) __u + 2);
419 __u->__uc = '\0';
420 break;
421 case 4:
422 __u->__ui = __src0_4;
423 break;
424 case 5:
425 __u->__ui = __src0_4;
426 __u = __extension__ ((void *) __u + 4);
427 __u->__uc = '\0';
428 break;
429 case 6:
430 __u->__ui = __src0_4;
431 __u = __extension__ ((void *) __u + 4);
432 __u->__usi = __src4_2;
433 break;
434 case 7:
435 __u->__ui = __src0_4;
436 __u = __extension__ ((void *) __u + 4);
437 __u->__usi = __src4_2;
438 __u = __extension__ ((void *) __u + 2);
439 __u->__uc = '\0';
440 break;
441 case 8:
442 __u->__ui = __src0_4;
443 __u = __extension__ ((void *) __u + 4);
444 __u->__ui = __src4_4;
445 break;
447 return __dest;
449 # else
450 # define __strcpy_args(src) \
451 __extension__ ((__STRING2_COPY_ARR2) \
452 { { ((__const char *) (src))[0], '\0' } }), \
453 __extension__ ((__STRING2_COPY_ARR3) \
454 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
455 '\0' } }), \
456 __extension__ ((__STRING2_COPY_ARR4) \
457 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
458 ((__const char *) (src))[2], '\0' } }), \
459 __extension__ ((__STRING2_COPY_ARR5) \
460 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
461 ((__const char *) (src))[2], ((__const char *) (src))[3], \
462 '\0' } }), \
463 __extension__ ((__STRING2_COPY_ARR6) \
464 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
465 ((__const char *) (src))[2], ((__const char *) (src))[3], \
466 ((__const char *) (src))[4], '\0' } }), \
467 __extension__ ((__STRING2_COPY_ARR7) \
468 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
469 ((__const char *) (src))[2], ((__const char *) (src))[3], \
470 ((__const char *) (src))[4], ((__const char *) (src))[5], \
471 '\0' } }), \
472 __extension__ ((__STRING2_COPY_ARR8) \
473 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
474 ((__const char *) (src))[2], ((__const char *) (src))[3], \
475 ((__const char *) (src))[4], ((__const char *) (src))[5], \
476 ((__const char *) (src))[6], '\0' } })
477 __STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2,
478 __STRING2_COPY_ARR3,
479 __STRING2_COPY_ARR4,
480 __STRING2_COPY_ARR5,
481 __STRING2_COPY_ARR6,
482 __STRING2_COPY_ARR7,
483 __STRING2_COPY_ARR8, size_t);
484 __STRING_INLINE char *
485 __strcpy_small (char *__dest,
486 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
487 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
488 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
489 __STRING2_COPY_ARR8 __src8, size_t __srclen)
491 union {
492 char __c;
493 __STRING2_COPY_ARR2 __sca2;
494 __STRING2_COPY_ARR3 __sca3;
495 __STRING2_COPY_ARR4 __sca4;
496 __STRING2_COPY_ARR5 __sca5;
497 __STRING2_COPY_ARR6 __sca6;
498 __STRING2_COPY_ARR7 __sca7;
499 __STRING2_COPY_ARR8 __sca8;
500 } *__u = (void *) __dest;
501 switch ((unsigned int) __srclen)
503 case 1:
504 __u->__c = '\0';
505 break;
506 case 2:
507 __extension__ __u->__sca2 = __src2;
508 break;
509 case 3:
510 __extension__ __u->__sca3 = __src3;
511 break;
512 case 4:
513 __extension__ __u->__sca4 = __src4;
514 break;
515 case 5:
516 __extension__ __u->__sca5 = __src5;
517 break;
518 case 6:
519 __extension__ __u->__sca6 = __src6;
520 break;
521 case 7:
522 __extension__ __u->__sca7 = __src7;
523 break;
524 case 8:
525 __extension__ __u->__sca8 = __src8;
526 break;
528 return __dest;
530 # endif
531 #endif
534 /* Copy SRC to DEST, returning pointer to final NUL byte. */
535 #ifdef __USE_GNU
536 # ifndef _HAVE_STRING_ARCH_stpcpy
537 # define __stpcpy(dest, src) \
538 (__extension__ (__builtin_constant_p (src) \
539 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
540 ? __stpcpy_small (dest, __stpcpy_args (src), \
541 strlen (src) + 1) \
542 : ((char *) __mempcpy (dest, src, strlen (src) + 1) - 1))\
543 : __stpcpy (dest, src)))
544 /* In glibc we use this function frequently but for namespace reasons
545 we have to use the name `__stpcpy'. */
546 # define stpcpy(dest, src) __stpcpy (dest, src)
548 # if _STRING_ARCH_unaligned
549 # define __stpcpy_args(src) \
550 __extension__ __STRING2_SMALL_GET16 (src, 0), \
551 __extension__ __STRING2_SMALL_GET16 (src, 4), \
552 __extension__ __STRING2_SMALL_GET32 (src, 0), \
553 __extension__ __STRING2_SMALL_GET32 (src, 4)
554 __STRING_INLINE char *__stpcpy_small (char *, __uint16_t, __uint16_t,
555 __uint32_t, __uint32_t, size_t);
556 __STRING_INLINE char *
557 __stpcpy_small (char *__dest,
558 __uint16_t __src0_2, __uint16_t __src4_2,
559 __uint32_t __src0_4, __uint32_t __src4_4,
560 size_t __srclen)
562 union {
563 unsigned int __ui;
564 unsigned short int __usi;
565 unsigned char __uc;
566 char __c;
567 } *__u = (void *) __dest;
568 switch ((unsigned int) __srclen)
570 case 1:
571 __u->__uc = '\0';
572 break;
573 case 2:
574 __u->__usi = __src0_2;
575 __u = __extension__ ((void *) __u + 1);
576 break;
577 case 3:
578 __u->__usi = __src0_2;
579 __u = __extension__ ((void *) __u + 2);
580 __u->__uc = '\0';
581 break;
582 case 4:
583 __u->__ui = __src0_4;
584 __u = __extension__ ((void *) __u + 3);
585 break;
586 case 5:
587 __u->__ui = __src0_4;
588 __u = __extension__ ((void *) __u + 4);
589 __u->__uc = '\0';
590 break;
591 case 6:
592 __u->__ui = __src0_4;
593 __u = __extension__ ((void *) __u + 4);
594 __u->__usi = __src4_2;
595 __u = __extension__ ((void *) __u + 1);
596 break;
597 case 7:
598 __u->__ui = __src0_4;
599 __u = __extension__ ((void *) __u + 4);
600 __u->__usi = __src4_2;
601 __u = __extension__ ((void *) __u + 2);
602 __u->__uc = '\0';
603 break;
604 case 8:
605 __u->__ui = __src0_4;
606 __u = __extension__ ((void *) __u + 4);
607 __u->__ui = __src4_4;
608 __u = __extension__ ((void *) __u + 3);
609 break;
611 return &__u->__c;
613 # else
614 # define __stpcpy_args(src) \
615 __extension__ ((__STRING2_COPY_ARR2) \
616 { { ((__const char *) (src))[0], '\0' } }), \
617 __extension__ ((__STRING2_COPY_ARR3) \
618 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
619 '\0' } }), \
620 __extension__ ((__STRING2_COPY_ARR4) \
621 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
622 ((__const char *) (src))[2], '\0' } }), \
623 __extension__ ((__STRING2_COPY_ARR5) \
624 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
625 ((__const char *) (src))[2], ((__const char *) (src))[3], \
626 '\0' } }), \
627 __extension__ ((__STRING2_COPY_ARR6) \
628 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
629 ((__const char *) (src))[2], ((__const char *) (src))[3], \
630 ((__const char *) (src))[4], '\0' } }), \
631 __extension__ ((__STRING2_COPY_ARR7) \
632 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
633 ((__const char *) (src))[2], ((__const char *) (src))[3], \
634 ((__const char *) (src))[4], ((__const char *) (src))[5], \
635 '\0' } }), \
636 __extension__ ((__STRING2_COPY_ARR8) \
637 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
638 ((__const char *) (src))[2], ((__const char *) (src))[3], \
639 ((__const char *) (src))[4], ((__const char *) (src))[5], \
640 ((__const char *) (src))[6], '\0' } })
641 __STRING_INLINE char *__stpcpy_small (char *, __STRING2_COPY_ARR2,
642 __STRING2_COPY_ARR3,
643 __STRING2_COPY_ARR4,
644 __STRING2_COPY_ARR5,
645 __STRING2_COPY_ARR6,
646 __STRING2_COPY_ARR7,
647 __STRING2_COPY_ARR8, size_t);
648 __STRING_INLINE char *
649 __stpcpy_small (char *__dest,
650 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
651 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
652 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
653 __STRING2_COPY_ARR8 __src8, size_t __srclen)
655 union {
656 char __c;
657 __STRING2_COPY_ARR2 __sca2;
658 __STRING2_COPY_ARR3 __sca3;
659 __STRING2_COPY_ARR4 __sca4;
660 __STRING2_COPY_ARR5 __sca5;
661 __STRING2_COPY_ARR6 __sca6;
662 __STRING2_COPY_ARR7 __sca7;
663 __STRING2_COPY_ARR8 __sca8;
664 } *__u = (void *) __dest;
665 switch ((unsigned int) __srclen)
667 case 1:
668 __u->__c = '\0';
669 break;
670 case 2:
671 __extension__ __u->__sca2 = __src2;
672 break;
673 case 3:
674 __extension__ __u->__sca3 = __src3;
675 break;
676 case 4:
677 __extension__ __u->__sca4 = __src4;
678 break;
679 case 5:
680 __extension__ __u->__sca5 = __src5;
681 break;
682 case 6:
683 __extension__ __u->__sca6 = __src6;
684 break;
685 case 7:
686 __extension__ __u->__sca7 = __src7;
687 break;
688 case 8:
689 __extension__ __u->__sca8 = __src8;
690 break;
692 return __dest + __srclen - 1;
694 # endif
695 # endif
696 #endif
699 /* Copy no more than N characters of SRC to DEST. */
700 #ifndef _HAVE_STRING_ARCH_strncpy
701 # if defined _USE_STRING_ARCH_memset && defined _USE_STRING_ARCH_mempcpy
702 # define strncpy(dest, src, n) \
703 (__extension__ ({ char *__dest = (dest); \
704 __builtin_constant_p (src) && __builtin_constant_p (n) \
705 ? (strlen (src) + 1 >= ((size_t) (n)) \
706 ? (char *) memcpy (__dest, src, n) \
707 : (memset (__mempcpy (__dest, src, strlen (src)), \
708 '\0', n - strlen (src)), \
709 __dest)) \
710 : strncpy (__dest, src, n); }))
711 # else
712 # define strncpy(dest, src, n) \
713 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
714 ? (strlen (src) + 1 >= ((size_t) (n)) \
715 ? (char *) memcpy (dest, src, n) \
716 : strncpy (dest, src, n)) \
717 : strncpy (dest, src, n)))
718 # endif
719 #endif
722 /* Append no more than N characters from SRC onto DEST. */
723 #ifndef _HAVE_STRING_ARCH_strncat
724 # ifdef _USE_STRING_ARCH_strchr
725 # define strncat(dest, src, n) \
726 (__extension__ ({ char *__dest = (dest); \
727 __builtin_constant_p (src) && __builtin_constant_p (n) \
728 ? (strlen (src) < ((size_t) (n)) \
729 ? strcat (__dest, src) \
730 : (*((char *) __mempcpy (strchr (__dest, '\0'), \
731 src, n)) = '\0', __dest)) \
732 : strncat (dest, src, n); }))
733 # else
734 # define strncat(dest, src, n) \
735 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
736 ? (strlen (src) < ((size_t) (n)) \
737 ? strcat (dest, src) \
738 : strncat (dest, src, n)) \
739 : strncat (dest, src, n)))
740 # endif
741 #endif
744 /* Compare characters of S1 and S2. */
745 #ifndef _HAVE_STRING_ARCH_strcmp
746 # define strcmp(s1, s2) \
747 __extension__ \
748 ({ size_t __s1_len, __s2_len; \
749 (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
750 && (__s1_len = strlen (s1), __s2_len = strlen (s2), \
751 (!__string2_1bptr_p (s1) || __s1_len >= 4) \
752 && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \
753 ? memcmp ((__const char *) (s1), (__const char *) (s2), \
754 (__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \
755 : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
756 && (__s1_len = strlen (s1), __s1_len < 4) \
757 ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
758 ? __strcmp_cc (s1, s2, __s1_len) \
759 : __strcmp_cg (s1, s2, __s1_len)) \
760 : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
761 && (__s2_len = strlen (s2), __s2_len < 4) \
762 ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
763 ? __strcmp_cc (s1, s2, __s2_len) \
764 : __strcmp_gc (s1, s2, __s2_len)) \
765 : strcmp (s1, s2)))); })
767 # define __strcmp_cc(s1, s2, l) \
768 (__extension__ ({ register int __result = \
769 (((__const unsigned char *) (__const char *) (s1))[0] \
770 - ((__const unsigned char *) (__const char *)(s2))[0]);\
771 if (l > 0 && __result == 0) \
773 __result = (((__const unsigned char *) \
774 (__const char *) (s1))[1] \
775 - ((__const unsigned char *) \
776 (__const char *) (s2))[1]); \
777 if (l > 1 && __result == 0) \
779 __result = \
780 (((__const unsigned char *) \
781 (__const char *) (s1))[2] \
782 - ((__const unsigned char *) \
783 (__const char *) (s2))[2]); \
784 if (l > 2 && __result == 0) \
785 __result = \
786 (((__const unsigned char *) \
787 (__const char *) (s1))[3] \
788 - ((__const unsigned char *) \
789 (__const char *) (s2))[3]); \
792 __result; }))
794 # define __strcmp_cg(s1, s2, l1) \
795 (__extension__ ({ __const unsigned char *__s2 = \
796 (__const unsigned char *) (__const char *) (s2); \
797 register int __result = \
798 (((__const unsigned char *) (__const char *) (s1))[0] \
799 - __s2[0]); \
800 if (l1 > 0 && __result == 0) \
802 __result = (((__const unsigned char *) \
803 (__const char *) (s1))[1] - __s2[1]); \
804 if (l1 > 1 && __result == 0) \
806 __result = (((__const unsigned char *) \
807 (__const char *) (s1))[2] - __s2[2]);\
808 if (l1 > 2 && __result == 0) \
809 __result = (((__const unsigned char *) \
810 (__const char *) (s1))[3] \
811 - __s2[3]); \
814 __result; }))
816 # define __strcmp_gc(s1, s2, l2) \
817 (__extension__ ({ __const unsigned char *__s1 = \
818 (__const unsigned char *) (__const char *) (s1); \
819 register int __result = \
820 __s1[0] - ((__const unsigned char *) \
821 (__const char *) (s2))[0]; \
822 if (l2 > 0 && __result == 0) \
824 __result = (__s1[1] \
825 - ((__const unsigned char *) \
826 (__const char *) (s2))[1]); \
827 if (l2 > 1 && __result == 0) \
829 __result = \
830 (__s1[2] - ((__const unsigned char *) \
831 (__const char *) (s2))[2]); \
832 if (l2 > 2 && __result == 0) \
833 __result = \
834 (__s1[3] \
835 - ((__const unsigned char *) \
836 (__const char *) (s2))[3]); \
839 __result; }))
840 #endif
843 /* Compare N characters of S1 and S2. */
844 #ifndef _HAVE_STRING_ARCH_strncmp
845 # define strncmp(s1, s2, n) \
846 (__extension__ (__builtin_constant_p (n) \
847 && ((__builtin_constant_p (s1) \
848 && strlen (s1) < ((size_t) (n))) \
849 || (__builtin_constant_p (s2) \
850 && strlen (s2) < ((size_t) (n)))) \
851 ? strcmp (s1, s2) : strncmp (s1, s2, n)))
852 #endif
855 /* Return the length of the initial segment of S which
856 consists entirely of characters not in REJECT. */
857 #ifndef _HAVE_STRING_ARCH_strcspn
858 # define strcspn(s, reject) \
859 __extension__ \
860 ({ char __r0, __r1, __r2; \
861 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
862 ? ((__r0 = ((__const char *) (reject))[0], __r0 == '\0') \
863 ? strlen (s) \
864 : ((__r1 = ((__const char *) (reject))[1], __r1 == '\0') \
865 ? __strcspn_c1 (s, __r0) \
866 : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
867 ? __strcspn_c2 (s, __r0, __r1) \
868 : (((__const char *) (reject))[3] == '\0' \
869 ? __strcspn_c3 (s, __r0, __r1, __r2) \
870 : strcspn (s, reject))))) \
871 : strcspn (s, reject)); })
873 __STRING_INLINE size_t __strcspn_c1 (__const char *__s, char __reject);
874 __STRING_INLINE size_t
875 __strcspn_c1 (__const char *__s, char __reject)
877 register size_t __result = 0;
878 while (__s[__result] != '\0' && __s[__result] != __reject)
879 ++__result;
880 return __result;
883 __STRING_INLINE size_t __strcspn_c2 (__const char *__s, char __reject1,
884 char __reject2);
885 __STRING_INLINE size_t
886 __strcspn_c2 (__const char *__s, char __reject1, char __reject2)
888 register size_t __result = 0;
889 while (__s[__result] != '\0' && __s[__result] != __reject1
890 && __s[__result] != __reject2)
891 ++__result;
892 return __result;
895 __STRING_INLINE size_t __strcspn_c3 (__const char *__s, char __reject1,
896 char __reject2, char __reject3);
897 __STRING_INLINE size_t
898 __strcspn_c3 (__const char *__s, char __reject1, char __reject2,
899 char __reject3)
901 register size_t __result = 0;
902 while (__s[__result] != '\0' && __s[__result] != __reject1
903 && __s[__result] != __reject2 && __s[__result] != __reject3)
904 ++__result;
905 return __result;
907 #endif
910 /* Return the length of the initial segment of S which
911 consists entirely of characters in ACCEPT. */
912 #ifndef _HAVE_STRING_ARCH_strspn
913 # define strspn(s, accept) \
914 __extension__ \
915 ({ char __a0, __a1, __a2; \
916 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
917 ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
918 ? ((void) (s), 0) \
919 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
920 ? __strspn_c1 (s, __a0) \
921 : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
922 ? __strspn_c2 (s, __a0, __a1) \
923 : (((__const char *) (accept))[3] == '\0' \
924 ? __strspn_c3 (s, __a0, __a1, __a2) \
925 : strspn (s, accept))))) \
926 : strspn (s, accept)); })
928 __STRING_INLINE size_t __strspn_c1 (__const char *__s, char __accept);
929 __STRING_INLINE size_t
930 __strspn_c1 (__const char *__s, char __accept)
932 register size_t __result = 0;
933 /* Please note that __accept never can be '\0'. */
934 while (__s[__result] == __accept)
935 ++__result;
936 return __result;
939 __STRING_INLINE size_t __strspn_c2 (__const char *__s, char __accept1,
940 char __accept2);
941 __STRING_INLINE size_t
942 __strspn_c2 (__const char *__s, char __accept1, char __accept2)
944 register size_t __result = 0;
945 /* Please note that __accept1 and __accept2 never can be '\0'. */
946 while (__s[__result] == __accept1 || __s[__result] == __accept2)
947 ++__result;
948 return __result;
951 __STRING_INLINE size_t __strspn_c3 (__const char *__s, char __accept1,
952 char __accept2, char __accept3);
953 __STRING_INLINE size_t
954 __strspn_c3 (__const char *__s, char __accept1, char __accept2, char __accept3)
956 register size_t __result = 0;
957 /* Please note that __accept1 to __accept3 never can be '\0'. */
958 while (__s[__result] == __accept1 || __s[__result] == __accept2
959 || __s[__result] == __accept3)
960 ++__result;
961 return __result;
963 #endif
966 /* Find the first occurrence in S of any character in ACCEPT. */
967 #ifndef _HAVE_STRING_ARCH_strpbrk
968 # define strpbrk(s, accept) \
969 __extension__ \
970 ({ char __a0, __a1, __a2; \
971 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
972 ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
973 ? ((void) (s), NULL) \
974 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
975 ? strchr (s, __a0) \
976 : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
977 ? __strpbrk_c2 (s, __a0, __a1) \
978 : (((__const char *) (accept))[3] == '\0' \
979 ? __strpbrk_c3 (s, __a0, __a1, __a2) \
980 : strpbrk (s, accept))))) \
981 : strpbrk (s, accept)); })
983 __STRING_INLINE char *__strpbrk_c2 (__const char *__s, int __accept1,
984 int __accept2);
985 __STRING_INLINE char *
986 __strpbrk_c2 (__const char *__s, int __accept1, int __accept2)
988 /* Please note that __accept1 and __accept2 never can be '\0'. */
989 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2)
990 ++__s;
991 return *__s == '\0' ? NULL : (char *) (size_t) __s;
994 __STRING_INLINE char *__strpbrk_c3 (__const char *__s, int __accept1,
995 int __accept2, int __accept3);
996 __STRING_INLINE char *
997 __strpbrk_c3 (__const char *__s, int __accept1, int __accept2,
998 int __accept3)
1000 /* Please note that __accept1 to __accept3 never can be '\0'. */
1001 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2
1002 && *__s != __accept3)
1003 ++__s;
1004 return *__s == '\0' ? NULL : (char *) (size_t) __s;
1006 #endif
1009 /* Find the first occurrence of NEEDLE in HAYSTACK. Newer gcc versions
1010 do this itself. */
1011 #if !defined _HAVE_STRING_ARCH_strstr && !__GNUC_PREREQ (2, 97)
1012 # define strstr(haystack, needle) \
1013 (__extension__ (__builtin_constant_p (needle) && __string2_1bptr_p (needle) \
1014 ? (((__const char *) (needle))[0] == '\0' \
1015 ? (char *) (size_t) (haystack) \
1016 : (((__const char *) (needle))[1] == '\0' \
1017 ? strchr (haystack, \
1018 ((__const char *) (needle))[0]) \
1019 : strstr (haystack, needle))) \
1020 : strstr (haystack, needle)))
1021 #endif
1024 #if defined __USE_GNU && !defined _FORCE_INLINES
1025 # ifndef _HAVE_STRING_ARCH_strnlen
1026 __STRING_INLINE size_t
1027 strnlen (__const char *__string, size_t __maxlen)
1029 __const char *__end = (__const char *) memchr (__string, '\0', __maxlen);
1030 return __end ? (size_t) (__end - __string) : __maxlen;
1032 # endif
1033 #endif
1036 #ifndef _HAVE_STRING_ARCH_strtok_r
1037 # define __strtok_r(s, sep, nextp) \
1038 (__extension__ (__builtin_constant_p (sep) && __string2_1bptr_p (sep) \
1039 ? (((__const char *) (sep))[0] != '\0' \
1040 && ((__const char *) (sep))[1] == '\0' \
1041 ? __strtok_r_1c (s, ((__const char *) (sep))[0], nextp) \
1042 : __strtok_r (s, sep, nextp)) \
1043 : __strtok_r (s, sep, nextp)))
1045 __STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp);
1046 __STRING_INLINE char *
1047 __strtok_r_1c (char *__s, char __sep, char **__nextp)
1049 char *__result;
1050 if (__s == NULL)
1051 __s = *__nextp;
1052 while (*__s == __sep)
1053 ++__s;
1054 if (*__s == '\0')
1055 __result = NULL;
1056 else
1058 __result = __s;
1059 while (*__s != '\0' && *__s != __sep)
1060 ++__s;
1061 if (*__s == '\0')
1062 *__nextp = __s;
1063 else
1065 *__s = '\0';
1066 *__nextp = __s + 1;
1069 return __result;
1071 # if defined __USE_POSIX || defined __USE_MISC
1072 # define strtok_r(s, sep, nextp) __strtok_r ((s), (sep), (nextp))
1073 # endif
1074 #endif
1077 #ifndef _HAVE_STRING_ARCH_strsep
1079 # define __strsep(s, reject) \
1080 __extension__ \
1081 ({ char __r0, __r1, __r2; \
1082 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
1083 && (__r0 = ((__const char *) (reject))[0], \
1084 ((__const char *) (reject))[0] != '\0') \
1085 ? ((__r1 = ((__const char *) (reject))[1], \
1086 ((__const char *) (reject))[1] == '\0') \
1087 ? __strsep_1c (s, __r0) \
1088 : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
1089 ? __strsep_2c (s, __r0, __r1) \
1090 : (((__const char *) (reject))[3] == '\0' \
1091 ? __strsep_3c (s, __r0, __r1, __r2) \
1092 : __strsep_g (s, reject)))) \
1093 : __strsep_g (s, reject)); })
1095 __STRING_INLINE char *__strsep_1c (char **__s, char __reject);
1096 __STRING_INLINE char *
1097 __strsep_1c (char **__s, char __reject)
1099 register char *__retval = *__s;
1100 if (__retval == NULL)
1101 return *__s = NULL;
1102 if (*__retval == __reject)
1103 *(*__s)++ = '\0';
1104 else
1105 if ((*__s = strchr (__retval, __reject)) != NULL)
1106 *(*__s)++ = '\0';
1107 else
1108 *__s = NULL;
1109 return __retval;
1112 __STRING_INLINE char *__strsep_2c (char **__s, char __reject1, char __reject2);
1113 __STRING_INLINE char *
1114 __strsep_2c (char **__s, char __reject1, char __reject2)
1116 register char *__retval = *__s;
1117 if (__retval == NULL)
1118 return *__s = NULL;
1119 if (*__retval == __reject1 || *__retval == __reject2)
1120 *(*__s)++ = '\0';
1121 else
1123 register char *__cp = __retval;
1124 while (*__cp != '\0' && *__cp != __reject1 && *__cp != __reject2)
1125 ++__cp;
1126 if (*__cp != '\0')
1128 *__s = __cp;
1129 *(*__s)++ = '\0';
1131 else
1132 *__s = NULL;
1134 return __retval;
1137 __STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2,
1138 char __reject3);
1139 __STRING_INLINE char *
1140 __strsep_3c (char **__s, char __reject1, char __reject2, char __reject3)
1142 register char *__retval = *__s;
1143 if (__retval == NULL)
1144 return *__s = NULL;
1145 if (*__retval == __reject1 || *__retval == __reject2
1146 || *__retval == __reject3)
1147 *(*__s)++ = '\0';
1148 else
1150 register char *__cp = __retval;
1151 while (*__cp != '\0' && *__cp != __reject1 && *__cp != __reject2
1152 && *__cp != __reject3)
1153 ++__cp;
1154 if (*__cp != '\0')
1156 *__s = __cp;
1157 *(*__s)++ = '\0';
1159 else
1160 *__s = NULL;
1162 return __retval;
1165 __STRING_INLINE char *__strsep_g (char **__s, __const char *__reject);
1166 __STRING_INLINE char *
1167 __strsep_g (char **__s, __const char *__reject)
1169 register char *__retval = *__s;
1170 if (__retval == NULL)
1171 return NULL;
1172 if ((*__s = strpbrk (__retval, __reject)) != NULL)
1173 *(*__s)++ = '\0';
1174 return __retval;
1176 # ifdef __USE_BSD
1177 # define strsep(s, reject) __strsep ((s), (reject))
1178 # endif
1179 #endif
1181 /* We need the memory allocation functions for inline strdup().
1182 Referring to stdlib.h (even minimally) is not allowed
1183 in any of the tight standards compliant modes. */
1184 #ifdef __USE_MISC
1186 # if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
1187 # define __need_malloc_and_calloc
1188 # include <stdlib.h>
1189 # endif
1191 # ifndef _HAVE_STRING_ARCH_strdup
1193 extern char *__strdup (__const char *__string) __THROW __attribute_malloc__;
1194 # define __strdup(s) \
1195 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1196 ? (((__const char *) (s))[0] == '\0' \
1197 ? (char *) calloc (1, 1) \
1198 : ({ size_t __len = strlen (s) + 1; \
1199 char *__retval = (char *) malloc (__len); \
1200 if (__retval != NULL) \
1201 __retval = (char *) memcpy (__retval, s, __len); \
1202 __retval; })) \
1203 : __strdup (s)))
1205 # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1206 # define strdup(s) __strdup (s)
1207 # endif
1208 # endif
1210 # ifndef _HAVE_STRING_ARCH_strndup
1212 extern char *__strndup (__const char *__string, size_t __n)
1213 __THROW __attribute_malloc__;
1214 # define __strndup(s, n) \
1215 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1216 ? (((__const char *) (s))[0] == '\0' \
1217 ? (char *) calloc (1, 1) \
1218 : ({ size_t __len = strlen (s) + 1; \
1219 size_t __n = (n); \
1220 char *__retval; \
1221 if (__n < __len) \
1222 __len = __n; \
1223 __retval = (char *) malloc (__len); \
1224 if (__retval != NULL) \
1226 __retval[__len - 1] = '\0'; \
1227 __retval = (char *) memcpy (__retval, s, \
1228 __len - 1); \
1230 __retval; })) \
1231 : __strndup ((s), (n))))
1233 # ifdef __USE_GNU
1234 # define strndup(s, n) __strndup ((s), (n))
1235 # endif
1236 # endif
1238 #endif /* Use misc. or use GNU. */
1240 #ifndef _FORCE_INLINES
1241 # undef __STRING_INLINE
1242 #endif
1244 #endif /* No string inlines. */