1 /* Copyright (C) 1999-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 /* <bits/string.h> may declare some extern inline functions.
19 These functions are defined here if inlining is not possible. */
21 #undef __USE_STRING_INLINES
22 #define __USE_STRING_INLINES
23 #define _FORCE_INLINES
24 #define __STRING_INLINE /* empty */
33 #include <bits/string.h>
34 #include "shlib-compat.h"
36 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_25)
37 /* The inline functions are not used from GLIBC 2.25 and forward, however
38 they are required to provide the symbols through string-inlines.c
39 (if inlining is not possible for compatibility reasons). */
42 __old_strtok_r_1c (char *__s
, char __sep
, char **__nextp
)
63 compat_symbol (libc
, __old_strtok_r_1c
, __strtok_r_1c
, GLIBC_2_1_1
);
66 __old_strsep_1c (char **__s
, char __reject
)
68 char *__retval
= *__s
;
69 if (__retval
!= NULL
&& (*__s
= strchr (__retval
, __reject
)) != NULL
)
73 compat_symbol (libc
, __old_strsep_1c
, __strsep_1c
, GLIBC_2_1_1
);
76 __old_strsep_2c (char **__s
, char __reject1
, char __reject2
)
78 char *__retval
= *__s
;
81 char *__cp
= __retval
;
89 if (*__cp
== __reject1
|| *__cp
== __reject2
)
100 compat_symbol (libc
, __old_strsep_2c
, __strsep_2c
, GLIBC_2_1_1
);
103 __old_strsep_3c (char **__s
, char __reject1
, char __reject2
, char __reject3
)
105 char *__retval
= *__s
;
106 if (__retval
!= NULL
)
108 char *__cp
= __retval
;
116 if (*__cp
== __reject1
|| *__cp
== __reject2
|| *__cp
== __reject3
)
127 compat_symbol (libc
, __old_strsep_3c
, __strsep_3c
, GLIBC_2_1_1
);
130 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24)
131 /* The inline functions are not used from GLIBC 2.24 and forward, however
132 they are required to provide the symbols through string-inlines.c
133 (if inlining is not possible for compatibility reasons). */
135 __old_strcspn_c1 (const char *__s
, int __reject
)
138 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
142 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
145 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
148 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
149 && __s
[__result
] != __reject2
)
153 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
156 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
160 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
161 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
165 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
168 __old_strspn_c1 (const char *__s
, int __accept
)
171 /* Please note that __accept never can be '\0'. */
172 while (__s
[__result
] == __accept
)
176 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
179 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
182 /* Please note that __accept1 and __accept2 never can be '\0'. */
183 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
187 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
190 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
194 /* Please note that __accept1 to __accept3 never can be '\0'. */
195 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
196 || __s
[__result
] == __accept3
)
200 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
203 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
205 /* Please note that __accept1 and __accept2 never can be '\0'. */
206 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
208 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
210 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
213 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
215 /* Please note that __accept1 to __accept3 never can be '\0'. */
216 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
217 && *__s
!= __accept3
)
219 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
221 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
223 /* These are a few types we need for the optimizations if we cannot
224 use unaligned memory accesses. */
225 # define __STRING2_COPY_TYPE(N) \
226 typedef struct { unsigned char __arr[N]; } \
227 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
228 __STRING2_COPY_TYPE (2);
229 __STRING2_COPY_TYPE (3);
230 __STRING2_COPY_TYPE (4);
231 __STRING2_COPY_TYPE (5);
232 __STRING2_COPY_TYPE (6);
233 __STRING2_COPY_TYPE (7);
234 __STRING2_COPY_TYPE (8);
235 # undef __STRING2_COPY_TYPE
238 # if _STRING_INLINE_unaligned
240 __old_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
,
252 switch ((unsigned int) __srclen
)
256 __u
= __extension__ ((void *) __u
+ 1);
259 __u
->__usi
= __src0_2
;
260 __u
= __extension__ ((void *) __u
+ 2);
263 __u
->__usi
= __src0_2
;
264 __u
= __extension__ ((void *) __u
+ 2);
266 __u
= __extension__ ((void *) __u
+ 1);
269 __u
->__ui
= __src0_4
;
270 __u
= __extension__ ((void *) __u
+ 4);
273 __u
->__ui
= __src0_4
;
274 __u
= __extension__ ((void *) __u
+ 4);
276 __u
= __extension__ ((void *) __u
+ 1);
279 __u
->__ui
= __src0_4
;
280 __u
= __extension__ ((void *) __u
+ 4);
281 __u
->__usi
= __src4_2
;
282 __u
= __extension__ ((void *) __u
+ 2);
285 __u
->__ui
= __src0_4
;
286 __u
= __extension__ ((void *) __u
+ 4);
287 __u
->__usi
= __src4_2
;
288 __u
= __extension__ ((void *) __u
+ 2);
290 __u
= __extension__ ((void *) __u
+ 1);
293 __u
->__ui
= __src0_4
;
294 __u
= __extension__ ((void *) __u
+ 4);
295 __u
->__ui
= __src4_4
;
296 __u
= __extension__ ((void *) __u
+ 4);
305 __old_mempcpy_small (void *__dest
, char __src1
,
306 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
307 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
308 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
309 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
313 __STRING2_COPY_ARR2 __sca2
;
314 __STRING2_COPY_ARR3 __sca3
;
315 __STRING2_COPY_ARR4 __sca4
;
316 __STRING2_COPY_ARR5 __sca5
;
317 __STRING2_COPY_ARR6 __sca6
;
318 __STRING2_COPY_ARR7 __sca7
;
319 __STRING2_COPY_ARR8 __sca8
;
321 switch ((unsigned int) __srclen
)
327 __extension__ __u
->__sca2
= __src2
;
330 __extension__ __u
->__sca3
= __src3
;
333 __extension__ __u
->__sca4
= __src4
;
336 __extension__ __u
->__sca5
= __src5
;
339 __extension__ __u
->__sca6
= __src6
;
342 __extension__ __u
->__sca7
= __src7
;
345 __extension__ __u
->__sca8
= __src8
;
348 return __extension__ ((void *) __u
+ __srclen
);
351 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
353 # if _STRING_INLINE_unaligned
355 __old_strcpy_small (char *__dest
,
356 __uint16_t __src0_2
, __uint16_t __src4_2
,
357 __uint32_t __src0_4
, __uint32_t __src4_4
,
364 } *__u
= (void *) __dest
;
365 switch ((unsigned int) __srclen
)
371 __u
->__usi
= __src0_2
;
374 __u
->__usi
= __src0_2
;
375 __u
= __extension__ ((void *) __u
+ 2);
379 __u
->__ui
= __src0_4
;
382 __u
->__ui
= __src0_4
;
383 __u
= __extension__ ((void *) __u
+ 4);
387 __u
->__ui
= __src0_4
;
388 __u
= __extension__ ((void *) __u
+ 4);
389 __u
->__usi
= __src4_2
;
392 __u
->__ui
= __src0_4
;
393 __u
= __extension__ ((void *) __u
+ 4);
394 __u
->__usi
= __src4_2
;
395 __u
= __extension__ ((void *) __u
+ 2);
399 __u
->__ui
= __src0_4
;
400 __u
= __extension__ ((void *) __u
+ 4);
401 __u
->__ui
= __src4_4
;
410 __old_strcpy_small (char *__dest
,
411 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
412 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
413 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
414 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
418 __STRING2_COPY_ARR2 __sca2
;
419 __STRING2_COPY_ARR3 __sca3
;
420 __STRING2_COPY_ARR4 __sca4
;
421 __STRING2_COPY_ARR5 __sca5
;
422 __STRING2_COPY_ARR6 __sca6
;
423 __STRING2_COPY_ARR7 __sca7
;
424 __STRING2_COPY_ARR8 __sca8
;
425 } *__u
= (void *) __dest
;
426 switch ((unsigned int) __srclen
)
432 __extension__ __u
->__sca2
= __src2
;
435 __extension__ __u
->__sca3
= __src3
;
438 __extension__ __u
->__sca4
= __src4
;
441 __extension__ __u
->__sca5
= __src5
;
444 __extension__ __u
->__sca6
= __src6
;
447 __extension__ __u
->__sca7
= __src7
;
450 __extension__ __u
->__sca8
= __src8
;
456 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
458 # if _STRING_INLINE_unaligned
460 __old_stpcpy_small (char *__dest
,
461 __uint16_t __src0_2
, __uint16_t __src4_2
,
462 __uint32_t __src0_4
, __uint32_t __src4_4
,
467 unsigned short int __usi
;
470 } *__u
= (void *) __dest
;
471 switch ((unsigned int) __srclen
)
477 __u
->__usi
= __src0_2
;
478 __u
= __extension__ ((void *) __u
+ 1);
481 __u
->__usi
= __src0_2
;
482 __u
= __extension__ ((void *) __u
+ 2);
486 __u
->__ui
= __src0_4
;
487 __u
= __extension__ ((void *) __u
+ 3);
490 __u
->__ui
= __src0_4
;
491 __u
= __extension__ ((void *) __u
+ 4);
495 __u
->__ui
= __src0_4
;
496 __u
= __extension__ ((void *) __u
+ 4);
497 __u
->__usi
= __src4_2
;
498 __u
= __extension__ ((void *) __u
+ 1);
501 __u
->__ui
= __src0_4
;
502 __u
= __extension__ ((void *) __u
+ 4);
503 __u
->__usi
= __src4_2
;
504 __u
= __extension__ ((void *) __u
+ 2);
508 __u
->__ui
= __src0_4
;
509 __u
= __extension__ ((void *) __u
+ 4);
510 __u
->__ui
= __src4_4
;
511 __u
= __extension__ ((void *) __u
+ 3);
520 __old_stpcpy_small (char *__dest
,
521 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
522 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
523 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
524 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
528 __STRING2_COPY_ARR2 __sca2
;
529 __STRING2_COPY_ARR3 __sca3
;
530 __STRING2_COPY_ARR4 __sca4
;
531 __STRING2_COPY_ARR5 __sca5
;
532 __STRING2_COPY_ARR6 __sca6
;
533 __STRING2_COPY_ARR7 __sca7
;
534 __STRING2_COPY_ARR8 __sca8
;
535 } *__u
= (void *) __dest
;
536 switch ((unsigned int) __srclen
)
542 __extension__ __u
->__sca2
= __src2
;
545 __extension__ __u
->__sca3
= __src3
;
548 __extension__ __u
->__sca4
= __src4
;
551 __extension__ __u
->__sca5
= __src5
;
554 __extension__ __u
->__sca6
= __src6
;
557 __extension__ __u
->__sca7
= __src7
;
560 __extension__ __u
->__sca8
= __src8
;
563 return __dest
+ __srclen
- 1;
566 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);