Update.
[glibc.git] / string / bits / string2.h
blobe8ac063e03c621768594bd7c61e16528f483d084
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 # if !defined _HAVE_STRING_ARCH_mempcpy || defined _FORCE_INLINES
200 # ifndef _HAVE_STRING_ARCH_mempcpy
201 # define __mempcpy(dest, src, n) \
202 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
203 && __string2_1bptr_p (src) && n <= 8 \
204 ? __mempcpy_small (dest, __mempcpy_args (src), n) \
205 : __mempcpy (dest, src, n)))
206 /* In glibc we use this function frequently but for namespace reasons
207 we have to use the name `__mempcpy'. */
208 # define mempcpy(dest, src, n) __mempcpy (dest, src, n)
209 # endif
211 # if _STRING_ARCH_unaligned
212 # ifndef _FORCE_INLINES
213 # define __mempcpy_args(src) \
214 ((__const char *) (src))[0], ((__const char *) (src))[2], \
215 ((__const char *) (src))[4], ((__const char *) (src))[6], \
216 __extension__ __STRING2_SMALL_GET16 (src, 0), \
217 __extension__ __STRING2_SMALL_GET16 (src, 4), \
218 __extension__ __STRING2_SMALL_GET32 (src, 0), \
219 __extension__ __STRING2_SMALL_GET32 (src, 4)
220 # endif
221 __STRING_INLINE void *__mempcpy_small (void *, char, char, char, char,
222 __uint16_t, __uint16_t, __uint32_t,
223 __uint32_t, size_t);
224 __STRING_INLINE void *
225 __mempcpy_small (void *__dest1,
226 char __src0_1, char __src2_1, char __src4_1, char __src6_1,
227 __uint16_t __src0_2, __uint16_t __src4_2,
228 __uint32_t __src0_4, __uint32_t __src4_4,
229 size_t __srclen)
231 union {
232 __uint32_t __ui;
233 __uint16_t __usi;
234 unsigned char __uc;
235 unsigned char __c;
236 } *__u = __dest1;
237 switch ((unsigned int) __srclen)
239 case 1:
240 __u->__c = __src0_1;
241 __u = __extension__ ((void *) __u + 1);
242 break;
243 case 2:
244 __u->__usi = __src0_2;
245 __u = __extension__ ((void *) __u + 2);
246 break;
247 case 3:
248 __u->__usi = __src0_2;
249 __u = __extension__ ((void *) __u + 2);
250 __u->__c = __src2_1;
251 __u = __extension__ ((void *) __u + 1);
252 break;
253 case 4:
254 __u->__ui = __src0_4;
255 __u = __extension__ ((void *) __u + 4);
256 break;
257 case 5:
258 __u->__ui = __src0_4;
259 __u = __extension__ ((void *) __u + 4);
260 __u->__c = __src4_1;
261 __u = __extension__ ((void *) __u + 1);
262 break;
263 case 6:
264 __u->__ui = __src0_4;
265 __u = __extension__ ((void *) __u + 4);
266 __u->__usi = __src4_2;
267 __u = __extension__ ((void *) __u + 2);
268 break;
269 case 7:
270 __u->__ui = __src0_4;
271 __u = __extension__ ((void *) __u + 4);
272 __u->__usi = __src4_2;
273 __u = __extension__ ((void *) __u + 2);
274 __u->__c = __src6_1;
275 __u = __extension__ ((void *) __u + 1);
276 break;
277 case 8:
278 __u->__ui = __src0_4;
279 __u = __extension__ ((void *) __u + 4);
280 __u->__ui = __src4_4;
281 __u = __extension__ ((void *) __u + 4);
282 break;
284 return (void *) __u;
286 # else
287 # ifndef _FORCE_INLINES
288 # define __mempcpy_args(src) \
289 ((__const char *) (src))[0], \
290 __extension__ ((__STRING2_COPY_ARR2) \
291 { { ((__const char *) (src))[0], ((__const char *) (src))[1] } }), \
292 __extension__ ((__STRING2_COPY_ARR3) \
293 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
294 ((__const char *) (src))[2] } }), \
295 __extension__ ((__STRING2_COPY_ARR4) \
296 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
297 ((__const char *) (src))[2], ((__const char *) (src))[3] } }), \
298 __extension__ ((__STRING2_COPY_ARR5) \
299 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
300 ((__const char *) (src))[2], ((__const char *) (src))[3], \
301 ((__const char *) (src))[4] } }), \
302 __extension__ ((__STRING2_COPY_ARR6) \
303 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
304 ((__const char *) (src))[2], ((__const char *) (src))[3], \
305 ((__const char *) (src))[4], ((__const char *) (src))[5] } }), \
306 __extension__ ((__STRING2_COPY_ARR7) \
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] } }), \
311 __extension__ ((__STRING2_COPY_ARR8) \
312 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
313 ((__const char *) (src))[2], ((__const char *) (src))[3], \
314 ((__const char *) (src))[4], ((__const char *) (src))[5], \
315 ((__const char *) (src))[6], ((__const char *) (src))[7] } })
316 # endif
317 __STRING_INLINE void *__mempcpy_small (void *, char, __STRING2_COPY_ARR2,
318 __STRING2_COPY_ARR3,
319 __STRING2_COPY_ARR4,
320 __STRING2_COPY_ARR5,
321 __STRING2_COPY_ARR6,
322 __STRING2_COPY_ARR7,
323 __STRING2_COPY_ARR8, size_t);
324 __STRING_INLINE void *
325 __mempcpy_small (void *__dest, char __src1,
326 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
327 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
328 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
329 __STRING2_COPY_ARR8 __src8, size_t __srclen)
331 union {
332 char __c;
333 __STRING2_COPY_ARR2 __sca2;
334 __STRING2_COPY_ARR3 __sca3;
335 __STRING2_COPY_ARR4 __sca4;
336 __STRING2_COPY_ARR5 __sca5;
337 __STRING2_COPY_ARR6 __sca6;
338 __STRING2_COPY_ARR7 __sca7;
339 __STRING2_COPY_ARR8 __sca8;
340 } *__u = __dest;
341 switch ((unsigned int) __srclen)
343 case 1:
344 __u->__c = __src1;
345 break;
346 case 2:
347 __extension__ __u->__sca2 = __src2;
348 break;
349 case 3:
350 __extension__ __u->__sca3 = __src3;
351 break;
352 case 4:
353 __extension__ __u->__sca4 = __src4;
354 break;
355 case 5:
356 __extension__ __u->__sca5 = __src5;
357 break;
358 case 6:
359 __extension__ __u->__sca6 = __src6;
360 break;
361 case 7:
362 __extension__ __u->__sca7 = __src7;
363 break;
364 case 8:
365 __extension__ __u->__sca8 = __src8;
366 break;
368 return __extension__ ((void *) __u + __srclen);
370 # endif
371 # endif
372 #endif
375 /* Return pointer to C in S. */
376 #ifndef _HAVE_STRING_ARCH_strchr
377 extern void *__rawmemchr (const void *__s, int __c);
378 # define strchr(s, c) \
379 (__extension__ (__builtin_constant_p (c) && (c) == '\0' \
380 ? (char *) __rawmemchr (s, c) \
381 : strchr (s, c)))
382 #endif
385 /* Copy SRC to DEST. */
386 #if !defined _HAVE_STRING_ARCH_strcpy || defined _FORCE_INLINES
387 # ifndef _HAVE_STRING_ARCH_strcpy
388 # define strcpy(dest, src) \
389 (__extension__ (__builtin_constant_p (src) \
390 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
391 ? __strcpy_small (dest, __strcpy_args (src), \
392 strlen (src) + 1) \
393 : (char *) memcpy (dest, src, strlen (src) + 1)) \
394 : strcpy (dest, src)))
395 # endif
397 # if _STRING_ARCH_unaligned
398 # ifndef _FORCE_INLINES
399 # define __strcpy_args(src) \
400 __extension__ __STRING2_SMALL_GET16 (src, 0), \
401 __extension__ __STRING2_SMALL_GET16 (src, 4), \
402 __extension__ __STRING2_SMALL_GET32 (src, 0), \
403 __extension__ __STRING2_SMALL_GET32 (src, 4)
404 # endif
405 __STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
406 __uint32_t, __uint32_t, size_t);
407 __STRING_INLINE char *
408 __strcpy_small (char *__dest,
409 __uint16_t __src0_2, __uint16_t __src4_2,
410 __uint32_t __src0_4, __uint32_t __src4_4,
411 size_t __srclen)
413 union {
414 __uint32_t __ui;
415 __uint16_t __usi;
416 unsigned char __uc;
417 } *__u = (void *) __dest;
418 switch ((unsigned int) __srclen)
420 case 1:
421 __u->__uc = '\0';
422 break;
423 case 2:
424 __u->__usi = __src0_2;
425 break;
426 case 3:
427 __u->__usi = __src0_2;
428 __u = __extension__ ((void *) __u + 2);
429 __u->__uc = '\0';
430 break;
431 case 4:
432 __u->__ui = __src0_4;
433 break;
434 case 5:
435 __u->__ui = __src0_4;
436 __u = __extension__ ((void *) __u + 4);
437 __u->__uc = '\0';
438 break;
439 case 6:
440 __u->__ui = __src0_4;
441 __u = __extension__ ((void *) __u + 4);
442 __u->__usi = __src4_2;
443 break;
444 case 7:
445 __u->__ui = __src0_4;
446 __u = __extension__ ((void *) __u + 4);
447 __u->__usi = __src4_2;
448 __u = __extension__ ((void *) __u + 2);
449 __u->__uc = '\0';
450 break;
451 case 8:
452 __u->__ui = __src0_4;
453 __u = __extension__ ((void *) __u + 4);
454 __u->__ui = __src4_4;
455 break;
457 return __dest;
459 # else
460 # ifndef _FORCE_INLINES
461 # define __strcpy_args(src) \
462 __extension__ ((__STRING2_COPY_ARR2) \
463 { { ((__const char *) (src))[0], '\0' } }), \
464 __extension__ ((__STRING2_COPY_ARR3) \
465 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
466 '\0' } }), \
467 __extension__ ((__STRING2_COPY_ARR4) \
468 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
469 ((__const char *) (src))[2], '\0' } }), \
470 __extension__ ((__STRING2_COPY_ARR5) \
471 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
472 ((__const char *) (src))[2], ((__const char *) (src))[3], \
473 '\0' } }), \
474 __extension__ ((__STRING2_COPY_ARR6) \
475 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
476 ((__const char *) (src))[2], ((__const char *) (src))[3], \
477 ((__const char *) (src))[4], '\0' } }), \
478 __extension__ ((__STRING2_COPY_ARR7) \
479 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
480 ((__const char *) (src))[2], ((__const char *) (src))[3], \
481 ((__const char *) (src))[4], ((__const char *) (src))[5], \
482 '\0' } }), \
483 __extension__ ((__STRING2_COPY_ARR8) \
484 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
485 ((__const char *) (src))[2], ((__const char *) (src))[3], \
486 ((__const char *) (src))[4], ((__const char *) (src))[5], \
487 ((__const char *) (src))[6], '\0' } })
488 # endif
489 __STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2,
490 __STRING2_COPY_ARR3,
491 __STRING2_COPY_ARR4,
492 __STRING2_COPY_ARR5,
493 __STRING2_COPY_ARR6,
494 __STRING2_COPY_ARR7,
495 __STRING2_COPY_ARR8, size_t);
496 __STRING_INLINE char *
497 __strcpy_small (char *__dest,
498 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
499 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
500 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
501 __STRING2_COPY_ARR8 __src8, size_t __srclen)
503 union {
504 char __c;
505 __STRING2_COPY_ARR2 __sca2;
506 __STRING2_COPY_ARR3 __sca3;
507 __STRING2_COPY_ARR4 __sca4;
508 __STRING2_COPY_ARR5 __sca5;
509 __STRING2_COPY_ARR6 __sca6;
510 __STRING2_COPY_ARR7 __sca7;
511 __STRING2_COPY_ARR8 __sca8;
512 } *__u = (void *) __dest;
513 switch ((unsigned int) __srclen)
515 case 1:
516 __u->__c = '\0';
517 break;
518 case 2:
519 __extension__ __u->__sca2 = __src2;
520 break;
521 case 3:
522 __extension__ __u->__sca3 = __src3;
523 break;
524 case 4:
525 __extension__ __u->__sca4 = __src4;
526 break;
527 case 5:
528 __extension__ __u->__sca5 = __src5;
529 break;
530 case 6:
531 __extension__ __u->__sca6 = __src6;
532 break;
533 case 7:
534 __extension__ __u->__sca7 = __src7;
535 break;
536 case 8:
537 __extension__ __u->__sca8 = __src8;
538 break;
540 return __dest;
542 # endif
543 #endif
546 /* Copy SRC to DEST, returning pointer to final NUL byte. */
547 #ifdef __USE_GNU
548 # if !defined _HAVE_STRING_ARCH_stpcpy || defined _FORCE_INLINES
549 # ifndef _HAVE_STRING_ARCH_stpcpy
550 # define __stpcpy(dest, src) \
551 (__extension__ (__builtin_constant_p (src) \
552 ? (__string2_1bptr_p (src) && strlen (src) + 1 <= 8 \
553 ? __stpcpy_small (dest, __stpcpy_args (src), \
554 strlen (src) + 1) \
555 : ((char *) __mempcpy (dest, src, strlen (src) + 1) - 1))\
556 : __stpcpy (dest, src)))
557 /* In glibc we use this function frequently but for namespace reasons
558 we have to use the name `__stpcpy'. */
559 # define stpcpy(dest, src) __stpcpy (dest, src)
560 # endif
562 # if _STRING_ARCH_unaligned
563 # ifndef _FORCE_INLINES
564 # define __stpcpy_args(src) \
565 __extension__ __STRING2_SMALL_GET16 (src, 0), \
566 __extension__ __STRING2_SMALL_GET16 (src, 4), \
567 __extension__ __STRING2_SMALL_GET32 (src, 0), \
568 __extension__ __STRING2_SMALL_GET32 (src, 4)
569 # endif
570 __STRING_INLINE char *__stpcpy_small (char *, __uint16_t, __uint16_t,
571 __uint32_t, __uint32_t, size_t);
572 __STRING_INLINE char *
573 __stpcpy_small (char *__dest,
574 __uint16_t __src0_2, __uint16_t __src4_2,
575 __uint32_t __src0_4, __uint32_t __src4_4,
576 size_t __srclen)
578 union {
579 unsigned int __ui;
580 unsigned short int __usi;
581 unsigned char __uc;
582 char __c;
583 } *__u = (void *) __dest;
584 switch ((unsigned int) __srclen)
586 case 1:
587 __u->__uc = '\0';
588 break;
589 case 2:
590 __u->__usi = __src0_2;
591 __u = __extension__ ((void *) __u + 1);
592 break;
593 case 3:
594 __u->__usi = __src0_2;
595 __u = __extension__ ((void *) __u + 2);
596 __u->__uc = '\0';
597 break;
598 case 4:
599 __u->__ui = __src0_4;
600 __u = __extension__ ((void *) __u + 3);
601 break;
602 case 5:
603 __u->__ui = __src0_4;
604 __u = __extension__ ((void *) __u + 4);
605 __u->__uc = '\0';
606 break;
607 case 6:
608 __u->__ui = __src0_4;
609 __u = __extension__ ((void *) __u + 4);
610 __u->__usi = __src4_2;
611 __u = __extension__ ((void *) __u + 1);
612 break;
613 case 7:
614 __u->__ui = __src0_4;
615 __u = __extension__ ((void *) __u + 4);
616 __u->__usi = __src4_2;
617 __u = __extension__ ((void *) __u + 2);
618 __u->__uc = '\0';
619 break;
620 case 8:
621 __u->__ui = __src0_4;
622 __u = __extension__ ((void *) __u + 4);
623 __u->__ui = __src4_4;
624 __u = __extension__ ((void *) __u + 3);
625 break;
627 return &__u->__c;
629 # else
630 # ifndef _FORCE_INLINES
631 # define __stpcpy_args(src) \
632 __extension__ ((__STRING2_COPY_ARR2) \
633 { { ((__const char *) (src))[0], '\0' } }), \
634 __extension__ ((__STRING2_COPY_ARR3) \
635 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
636 '\0' } }), \
637 __extension__ ((__STRING2_COPY_ARR4) \
638 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
639 ((__const char *) (src))[2], '\0' } }), \
640 __extension__ ((__STRING2_COPY_ARR5) \
641 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
642 ((__const char *) (src))[2], ((__const char *) (src))[3], \
643 '\0' } }), \
644 __extension__ ((__STRING2_COPY_ARR6) \
645 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
646 ((__const char *) (src))[2], ((__const char *) (src))[3], \
647 ((__const char *) (src))[4], '\0' } }), \
648 __extension__ ((__STRING2_COPY_ARR7) \
649 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
650 ((__const char *) (src))[2], ((__const char *) (src))[3], \
651 ((__const char *) (src))[4], ((__const char *) (src))[5], \
652 '\0' } }), \
653 __extension__ ((__STRING2_COPY_ARR8) \
654 { { ((__const char *) (src))[0], ((__const char *) (src))[1], \
655 ((__const char *) (src))[2], ((__const char *) (src))[3], \
656 ((__const char *) (src))[4], ((__const char *) (src))[5], \
657 ((__const char *) (src))[6], '\0' } })
658 # endif
659 __STRING_INLINE char *__stpcpy_small (char *, __STRING2_COPY_ARR2,
660 __STRING2_COPY_ARR3,
661 __STRING2_COPY_ARR4,
662 __STRING2_COPY_ARR5,
663 __STRING2_COPY_ARR6,
664 __STRING2_COPY_ARR7,
665 __STRING2_COPY_ARR8, size_t);
666 __STRING_INLINE char *
667 __stpcpy_small (char *__dest,
668 __STRING2_COPY_ARR2 __src2, __STRING2_COPY_ARR3 __src3,
669 __STRING2_COPY_ARR4 __src4, __STRING2_COPY_ARR5 __src5,
670 __STRING2_COPY_ARR6 __src6, __STRING2_COPY_ARR7 __src7,
671 __STRING2_COPY_ARR8 __src8, size_t __srclen)
673 union {
674 char __c;
675 __STRING2_COPY_ARR2 __sca2;
676 __STRING2_COPY_ARR3 __sca3;
677 __STRING2_COPY_ARR4 __sca4;
678 __STRING2_COPY_ARR5 __sca5;
679 __STRING2_COPY_ARR6 __sca6;
680 __STRING2_COPY_ARR7 __sca7;
681 __STRING2_COPY_ARR8 __sca8;
682 } *__u = (void *) __dest;
683 switch ((unsigned int) __srclen)
685 case 1:
686 __u->__c = '\0';
687 break;
688 case 2:
689 __extension__ __u->__sca2 = __src2;
690 break;
691 case 3:
692 __extension__ __u->__sca3 = __src3;
693 break;
694 case 4:
695 __extension__ __u->__sca4 = __src4;
696 break;
697 case 5:
698 __extension__ __u->__sca5 = __src5;
699 break;
700 case 6:
701 __extension__ __u->__sca6 = __src6;
702 break;
703 case 7:
704 __extension__ __u->__sca7 = __src7;
705 break;
706 case 8:
707 __extension__ __u->__sca8 = __src8;
708 break;
710 return __dest + __srclen - 1;
712 # endif
713 # endif
714 #endif
717 /* Copy no more than N characters of SRC to DEST. */
718 #ifndef _HAVE_STRING_ARCH_strncpy
719 # if defined _USE_STRING_ARCH_memset && defined _USE_STRING_ARCH_mempcpy
720 # define strncpy(dest, src, n) \
721 (__extension__ ({ char *__dest = (dest); \
722 __builtin_constant_p (src) && __builtin_constant_p (n) \
723 ? (strlen (src) + 1 >= ((size_t) (n)) \
724 ? (char *) memcpy (__dest, src, n) \
725 : (memset (__mempcpy (__dest, src, strlen (src)), \
726 '\0', n - strlen (src)), \
727 __dest)) \
728 : strncpy (__dest, src, n); }))
729 # else
730 # define strncpy(dest, src, n) \
731 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
732 ? (strlen (src) + 1 >= ((size_t) (n)) \
733 ? (char *) memcpy (dest, src, n) \
734 : strncpy (dest, src, n)) \
735 : strncpy (dest, src, n)))
736 # endif
737 #endif
740 /* Append no more than N characters from SRC onto DEST. */
741 #ifndef _HAVE_STRING_ARCH_strncat
742 # ifdef _USE_STRING_ARCH_strchr
743 # define strncat(dest, src, n) \
744 (__extension__ ({ char *__dest = (dest); \
745 __builtin_constant_p (src) && __builtin_constant_p (n) \
746 ? (strlen (src) < ((size_t) (n)) \
747 ? strcat (__dest, src) \
748 : (*((char *) __mempcpy (strchr (__dest, '\0'), \
749 src, n)) = '\0', __dest)) \
750 : strncat (dest, src, n); }))
751 # else
752 # define strncat(dest, src, n) \
753 (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n) \
754 ? (strlen (src) < ((size_t) (n)) \
755 ? strcat (dest, src) \
756 : strncat (dest, src, n)) \
757 : strncat (dest, src, n)))
758 # endif
759 #endif
762 /* Compare characters of S1 and S2. */
763 #ifndef _HAVE_STRING_ARCH_strcmp
764 # define strcmp(s1, s2) \
765 __extension__ \
766 ({ size_t __s1_len, __s2_len; \
767 (__builtin_constant_p (s1) && __builtin_constant_p (s2) \
768 && (__s1_len = strlen (s1), __s2_len = strlen (s2), \
769 (!__string2_1bptr_p (s1) || __s1_len >= 4) \
770 && (!__string2_1bptr_p (s2) || __s2_len >= 4)) \
771 ? memcmp ((__const char *) (s1), (__const char *) (s2), \
772 (__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \
773 : (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
774 && (__s1_len = strlen (s1), __s1_len < 4) \
775 ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
776 ? __strcmp_cc (s1, s2, __s1_len) \
777 : __strcmp_cg (s1, s2, __s1_len)) \
778 : (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
779 && (__s2_len = strlen (s2), __s2_len < 4) \
780 ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
781 ? __strcmp_cc (s1, s2, __s2_len) \
782 : __strcmp_gc (s1, s2, __s2_len)) \
783 : strcmp (s1, s2)))); })
785 # define __strcmp_cc(s1, s2, l) \
786 (__extension__ ({ register int __result = \
787 (((__const unsigned char *) (__const char *) (s1))[0] \
788 - ((__const unsigned char *) (__const char *)(s2))[0]);\
789 if (l > 0 && __result == 0) \
791 __result = (((__const unsigned char *) \
792 (__const char *) (s1))[1] \
793 - ((__const unsigned char *) \
794 (__const char *) (s2))[1]); \
795 if (l > 1 && __result == 0) \
797 __result = \
798 (((__const unsigned char *) \
799 (__const char *) (s1))[2] \
800 - ((__const unsigned char *) \
801 (__const char *) (s2))[2]); \
802 if (l > 2 && __result == 0) \
803 __result = \
804 (((__const unsigned char *) \
805 (__const char *) (s1))[3] \
806 - ((__const unsigned char *) \
807 (__const char *) (s2))[3]); \
810 __result; }))
812 # define __strcmp_cg(s1, s2, l1) \
813 (__extension__ ({ __const unsigned char *__s2 = \
814 (__const unsigned char *) (__const char *) (s2); \
815 register int __result = \
816 (((__const unsigned char *) (__const char *) (s1))[0] \
817 - __s2[0]); \
818 if (l1 > 0 && __result == 0) \
820 __result = (((__const unsigned char *) \
821 (__const char *) (s1))[1] - __s2[1]); \
822 if (l1 > 1 && __result == 0) \
824 __result = (((__const unsigned char *) \
825 (__const char *) (s1))[2] - __s2[2]);\
826 if (l1 > 2 && __result == 0) \
827 __result = (((__const unsigned char *) \
828 (__const char *) (s1))[3] \
829 - __s2[3]); \
832 __result; }))
834 # define __strcmp_gc(s1, s2, l2) \
835 (__extension__ ({ __const unsigned char *__s1 = \
836 (__const unsigned char *) (__const char *) (s1); \
837 register int __result = \
838 __s1[0] - ((__const unsigned char *) \
839 (__const char *) (s2))[0]; \
840 if (l2 > 0 && __result == 0) \
842 __result = (__s1[1] \
843 - ((__const unsigned char *) \
844 (__const char *) (s2))[1]); \
845 if (l2 > 1 && __result == 0) \
847 __result = \
848 (__s1[2] - ((__const unsigned char *) \
849 (__const char *) (s2))[2]); \
850 if (l2 > 2 && __result == 0) \
851 __result = \
852 (__s1[3] \
853 - ((__const unsigned char *) \
854 (__const char *) (s2))[3]); \
857 __result; }))
858 #endif
861 /* Compare N characters of S1 and S2. */
862 #ifndef _HAVE_STRING_ARCH_strncmp
863 # define strncmp(s1, s2, n) \
864 (__extension__ (__builtin_constant_p (n) \
865 && ((__builtin_constant_p (s1) \
866 && strlen (s1) < ((size_t) (n))) \
867 || (__builtin_constant_p (s2) \
868 && strlen (s2) < ((size_t) (n)))) \
869 ? strcmp (s1, s2) : strncmp (s1, s2, n)))
870 #endif
873 /* Return the length of the initial segment of S which
874 consists entirely of characters not in REJECT. */
875 #if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES
876 # ifndef _HAVE_STRING_ARCH_strcspn
877 # define strcspn(s, reject) \
878 __extension__ \
879 ({ char __r0, __r1, __r2; \
880 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
881 ? ((__r0 = ((__const char *) (reject))[0], __r0 == '\0') \
882 ? strlen (s) \
883 : ((__r1 = ((__const char *) (reject))[1], __r1 == '\0') \
884 ? __strcspn_c1 (s, __r0) \
885 : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
886 ? __strcspn_c2 (s, __r0, __r1) \
887 : (((__const char *) (reject))[3] == '\0' \
888 ? __strcspn_c3 (s, __r0, __r1, __r2) \
889 : strcspn (s, reject))))) \
890 : strcspn (s, reject)); })
891 # endif
893 __STRING_INLINE size_t __strcspn_c1 (__const char *__s, int __reject);
894 __STRING_INLINE size_t
895 __strcspn_c1 (__const char *__s, int __reject)
897 register size_t __result = 0;
898 while (__s[__result] != '\0' && __s[__result] != __reject)
899 ++__result;
900 return __result;
903 __STRING_INLINE size_t __strcspn_c2 (__const char *__s, int __reject1,
904 int __reject2);
905 __STRING_INLINE size_t
906 __strcspn_c2 (__const char *__s, int __reject1, int __reject2)
908 register size_t __result = 0;
909 while (__s[__result] != '\0' && __s[__result] != __reject1
910 && __s[__result] != __reject2)
911 ++__result;
912 return __result;
915 __STRING_INLINE size_t __strcspn_c3 (__const char *__s, int __reject1,
916 int __reject2, int __reject3);
917 __STRING_INLINE size_t
918 __strcspn_c3 (__const char *__s, int __reject1, int __reject2,
919 int __reject3)
921 register size_t __result = 0;
922 while (__s[__result] != '\0' && __s[__result] != __reject1
923 && __s[__result] != __reject2 && __s[__result] != __reject3)
924 ++__result;
925 return __result;
927 #endif
930 /* Return the length of the initial segment of S which
931 consists entirely of characters in ACCEPT. */
932 #if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES
933 # ifndef _HAVE_STRING_ARCH_strspn
934 # define strspn(s, accept) \
935 __extension__ \
936 ({ char __a0, __a1, __a2; \
937 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
938 ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
939 ? ((void) (s), 0) \
940 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
941 ? __strspn_c1 (s, __a0) \
942 : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
943 ? __strspn_c2 (s, __a0, __a1) \
944 : (((__const char *) (accept))[3] == '\0' \
945 ? __strspn_c3 (s, __a0, __a1, __a2) \
946 : strspn (s, accept))))) \
947 : strspn (s, accept)); })
948 # endif
950 __STRING_INLINE size_t __strspn_c1 (__const char *__s, int __accept);
951 __STRING_INLINE size_t
952 __strspn_c1 (__const char *__s, int __accept)
954 register size_t __result = 0;
955 /* Please note that __accept never can be '\0'. */
956 while (__s[__result] == __accept)
957 ++__result;
958 return __result;
961 __STRING_INLINE size_t __strspn_c2 (__const char *__s, int __accept1,
962 int __accept2);
963 __STRING_INLINE size_t
964 __strspn_c2 (__const char *__s, int __accept1, int __accept2)
966 register size_t __result = 0;
967 /* Please note that __accept1 and __accept2 never can be '\0'. */
968 while (__s[__result] == __accept1 || __s[__result] == __accept2)
969 ++__result;
970 return __result;
973 __STRING_INLINE size_t __strspn_c3 (__const char *__s, int __accept1,
974 int __accept2, int __accept3);
975 __STRING_INLINE size_t
976 __strspn_c3 (__const char *__s, int __accept1, int __accept2, int __accept3)
978 register size_t __result = 0;
979 /* Please note that __accept1 to __accept3 never can be '\0'. */
980 while (__s[__result] == __accept1 || __s[__result] == __accept2
981 || __s[__result] == __accept3)
982 ++__result;
983 return __result;
985 #endif
988 /* Find the first occurrence in S of any character in ACCEPT. */
989 #if !defined _HAVE_STRING_ARCH_strpbrk || defined _FORCE_INLINES
990 # ifndef _HAVE_STRING_ARCH_strpbrk
991 # define strpbrk(s, accept) \
992 __extension__ \
993 ({ char __a0, __a1, __a2; \
994 (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
995 ? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
996 ? ((void) (s), NULL) \
997 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
998 ? strchr (s, __a0) \
999 : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
1000 ? __strpbrk_c2 (s, __a0, __a1) \
1001 : (((__const char *) (accept))[3] == '\0' \
1002 ? __strpbrk_c3 (s, __a0, __a1, __a2) \
1003 : strpbrk (s, accept))))) \
1004 : strpbrk (s, accept)); })
1005 # endif
1007 __STRING_INLINE char *__strpbrk_c2 (__const char *__s, int __accept1,
1008 int __accept2);
1009 __STRING_INLINE char *
1010 __strpbrk_c2 (__const char *__s, int __accept1, int __accept2)
1012 /* Please note that __accept1 and __accept2 never can be '\0'. */
1013 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2)
1014 ++__s;
1015 return *__s == '\0' ? NULL : (char *) (size_t) __s;
1018 __STRING_INLINE char *__strpbrk_c3 (__const char *__s, int __accept1,
1019 int __accept2, int __accept3);
1020 __STRING_INLINE char *
1021 __strpbrk_c3 (__const char *__s, int __accept1, int __accept2,
1022 int __accept3)
1024 /* Please note that __accept1 to __accept3 never can be '\0'. */
1025 while (*__s != '\0' && *__s != __accept1 && *__s != __accept2
1026 && *__s != __accept3)
1027 ++__s;
1028 return *__s == '\0' ? NULL : (char *) (size_t) __s;
1030 #endif
1033 /* Find the first occurrence of NEEDLE in HAYSTACK. Newer gcc versions
1034 do this itself. */
1035 #if !defined _HAVE_STRING_ARCH_strstr && !__GNUC_PREREQ (2, 97)
1036 # define strstr(haystack, needle) \
1037 (__extension__ (__builtin_constant_p (needle) && __string2_1bptr_p (needle) \
1038 ? (((__const char *) (needle))[0] == '\0' \
1039 ? (char *) (size_t) (haystack) \
1040 : (((__const char *) (needle))[1] == '\0' \
1041 ? strchr (haystack, \
1042 ((__const char *) (needle))[0]) \
1043 : strstr (haystack, needle))) \
1044 : strstr (haystack, needle)))
1045 #endif
1048 #if !defined _HAVE_STRING_ARCH_strtok_r || defined _FORCE_INLINES
1049 # ifndef _HAVE_STRING_ARCH_strtok_r
1050 # define __strtok_r(s, sep, nextp) \
1051 (__extension__ (__builtin_constant_p (sep) && __string2_1bptr_p (sep) \
1052 ? (((__const char *) (sep))[0] != '\0' \
1053 && ((__const char *) (sep))[1] == '\0' \
1054 ? __strtok_r_1c (s, ((__const char *) (sep))[0], nextp) \
1055 : __strtok_r (s, sep, nextp)) \
1056 : __strtok_r (s, sep, nextp)))
1057 # endif
1059 __STRING_INLINE char *__strtok_r_1c (char *__s, char __sep, char **__nextp);
1060 __STRING_INLINE char *
1061 __strtok_r_1c (char *__s, char __sep, char **__nextp)
1063 char *__result;
1064 if (__s == NULL)
1065 __s = *__nextp;
1066 while (*__s == __sep)
1067 ++__s;
1068 __result = NULL;
1069 if (*__s != '\0')
1071 __result = __s++;
1072 while (*__s != '\0')
1073 if (*__s++ == __sep)
1075 __s[-1] = '\0';
1076 break;
1078 *__nextp = __s;
1080 return __result;
1082 # if defined __USE_POSIX || defined __USE_MISC
1083 # define strtok_r(s, sep, nextp) __strtok_r (s, sep, nextp)
1084 # endif
1085 #endif
1088 #if !defined _HAVE_STRING_ARCH_strsep || defined _FORCE_INLINES
1089 # ifndef _HAVE_STRING_ARCH_strsep
1091 extern char *__strsep_g (char **__stringp, __const char *__delim);
1092 # define __strsep(s, reject) \
1093 __extension__ \
1094 ({ char __r0, __r1, __r2; \
1095 (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
1096 && (__r0 = ((__const char *) (reject))[0], \
1097 ((__const char *) (reject))[0] != '\0') \
1098 ? ((__r1 = ((__const char *) (reject))[1], \
1099 ((__const char *) (reject))[1] == '\0') \
1100 ? __strsep_1c (s, __r0) \
1101 : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \
1102 ? __strsep_2c (s, __r0, __r1) \
1103 : (((__const char *) (reject))[3] == '\0' \
1104 ? __strsep_3c (s, __r0, __r1, __r2) \
1105 : __strsep_g (s, reject)))) \
1106 : __strsep_g (s, reject)); })
1107 # endif
1109 __STRING_INLINE char *__strsep_1c (char **__s, char __reject);
1110 __STRING_INLINE char *
1111 __strsep_1c (char **__s, char __reject)
1113 register char *__retval = *__s;
1114 if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL)
1115 *(*__s)++ = '\0';
1116 return __retval;
1119 __STRING_INLINE char *__strsep_2c (char **__s, char __reject1, char __reject2);
1120 __STRING_INLINE char *
1121 __strsep_2c (char **__s, char __reject1, char __reject2)
1123 register char *__retval = *__s;
1124 if (__retval != NULL)
1126 register char *__cp = __retval;
1127 while (1)
1129 if (*__cp == '\0')
1131 __cp = NULL;
1132 break;
1134 if (*__cp == __reject1 || *__cp == __reject2)
1136 *__cp++ = '\0';
1137 break;
1139 ++__cp;
1141 *__s = __cp;
1143 return __retval;
1146 __STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2,
1147 char __reject3);
1148 __STRING_INLINE char *
1149 __strsep_3c (char **__s, char __reject1, char __reject2, char __reject3)
1151 register char *__retval = *__s;
1152 if (__retval != NULL)
1154 register char *__cp = __retval;
1155 while (1)
1157 if (*__cp == '\0')
1159 __cp = NULL;
1160 break;
1162 if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3)
1164 *__cp++ = '\0';
1165 break;
1167 ++__cp;
1169 *__s = __cp;
1171 return __retval;
1173 # ifdef __USE_BSD
1174 # define strsep(s, reject) __strsep (s, reject)
1175 # endif
1176 #endif
1178 /* We need the memory allocation functions for inline strdup().
1179 Referring to stdlib.h (even minimally) is not allowed
1180 in any of the tight standards compliant modes. */
1181 #ifdef __USE_MISC
1183 # if !defined _HAVE_STRING_ARCH_strdup || !defined _HAVE_STRING_ARCH_strndup
1184 # define __need_malloc_and_calloc
1185 # include <stdlib.h>
1186 # endif
1188 # ifndef _HAVE_STRING_ARCH_strdup
1190 extern char *__strdup (__const char *__string) __THROW __attribute_malloc__;
1191 # define __strdup(s) \
1192 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1193 ? (((__const char *) (s))[0] == '\0' \
1194 ? (char *) calloc (1, 1) \
1195 : ({ size_t __len = strlen (s) + 1; \
1196 char *__retval = (char *) malloc (__len); \
1197 if (__retval != NULL) \
1198 __retval = (char *) memcpy (__retval, s, __len); \
1199 __retval; })) \
1200 : __strdup (s)))
1202 # if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
1203 # define strdup(s) __strdup (s)
1204 # endif
1205 # endif
1207 # ifndef _HAVE_STRING_ARCH_strndup
1209 extern char *__strndup (__const char *__string, size_t __n)
1210 __THROW __attribute_malloc__;
1211 # define __strndup(s, n) \
1212 (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s) \
1213 ? (((__const char *) (s))[0] == '\0' \
1214 ? (char *) calloc (1, 1) \
1215 : ({ size_t __len = strlen (s) + 1; \
1216 size_t __n = (n); \
1217 char *__retval; \
1218 if (__n < __len) \
1219 __len = __n + 1; \
1220 __retval = (char *) malloc (__len); \
1221 if (__retval != NULL) \
1223 __retval[__len - 1] = '\0'; \
1224 __retval = (char *) memcpy (__retval, s, \
1225 __len - 1); \
1227 __retval; })) \
1228 : __strndup (s, n)))
1230 # ifdef __USE_GNU
1231 # define strndup(s, n) __strndup (s, n)
1232 # endif
1233 # endif
1235 #endif /* Use misc. or use GNU. */
1237 #ifndef _FORCE_INLINES
1238 # undef __STRING_INLINE
1239 #endif
1241 #endif /* No string inlines. */