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 */
32 #include <bits/string.h>
33 #include "shlib-compat.h"
35 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_25)
36 /* The inline functions are not used from GLIBC 2.25 and forward, however
37 they are required to provide the symbols through string-inlines.c
38 (if inlining is not possible for compatibility reasons). */
41 __old_strtok_r_1c (char *__s
, char __sep
, char **__nextp
)
62 compat_symbol (libc
, __old_strtok_r_1c
, __strtok_r_1c
, GLIBC_2_1_1
);
65 __old_strsep_1c (char **__s
, char __reject
)
67 char *__retval
= *__s
;
68 if (__retval
!= NULL
&& (*__s
= strchr (__retval
, __reject
)) != NULL
)
72 compat_symbol (libc
, __old_strsep_1c
, __strsep_1c
, GLIBC_2_1_1
);
75 __old_strsep_2c (char **__s
, char __reject1
, char __reject2
)
77 char *__retval
= *__s
;
80 char *__cp
= __retval
;
88 if (*__cp
== __reject1
|| *__cp
== __reject2
)
99 compat_symbol (libc
, __old_strsep_2c
, __strsep_2c
, GLIBC_2_1_1
);
102 __old_strsep_3c (char **__s
, char __reject1
, char __reject2
, char __reject3
)
104 char *__retval
= *__s
;
105 if (__retval
!= NULL
)
107 char *__cp
= __retval
;
115 if (*__cp
== __reject1
|| *__cp
== __reject2
|| *__cp
== __reject3
)
126 compat_symbol (libc
, __old_strsep_3c
, __strsep_3c
, GLIBC_2_1_1
);
129 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24)
130 /* The inline functions are not used from GLIBC 2.24 and forward, however
131 they are required to provide the symbols through string-inlines.c
132 (if inlining is not possible for compatibility reasons). */
134 __old_strcspn_c1 (const char *__s
, int __reject
)
137 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
141 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
144 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
147 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
148 && __s
[__result
] != __reject2
)
152 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
155 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
159 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
160 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
164 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
167 __old_strspn_c1 (const char *__s
, int __accept
)
170 /* Please note that __accept never can be '\0'. */
171 while (__s
[__result
] == __accept
)
175 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
178 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
181 /* Please note that __accept1 and __accept2 never can be '\0'. */
182 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
186 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
189 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
193 /* Please note that __accept1 to __accept3 never can be '\0'. */
194 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
195 || __s
[__result
] == __accept3
)
199 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
202 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
204 /* Please note that __accept1 and __accept2 never can be '\0'. */
205 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
207 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
209 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
212 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
214 /* Please note that __accept1 to __accept3 never can be '\0'. */
215 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
216 && *__s
!= __accept3
)
218 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
220 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
222 /* These are a few types we need for the optimizations if we cannot
223 use unaligned memory accesses. */
224 # define __STRING2_COPY_TYPE(N) \
225 typedef struct { unsigned char __arr[N]; } \
226 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
227 __STRING2_COPY_TYPE (2);
228 __STRING2_COPY_TYPE (3);
229 __STRING2_COPY_TYPE (4);
230 __STRING2_COPY_TYPE (5);
231 __STRING2_COPY_TYPE (6);
232 __STRING2_COPY_TYPE (7);
233 __STRING2_COPY_TYPE (8);
234 # undef __STRING2_COPY_TYPE
237 # if _STRING_INLINE_unaligned
239 __old_mempcpy_small (void *__dest1
,
240 char __src0_1
, char __src2_1
, char __src4_1
, char __src6_1
,
241 __uint16_t __src0_2
, __uint16_t __src4_2
,
242 __uint32_t __src0_4
, __uint32_t __src4_4
,
251 switch ((unsigned int) __srclen
)
255 __u
= __extension__ ((void *) __u
+ 1);
258 __u
->__usi
= __src0_2
;
259 __u
= __extension__ ((void *) __u
+ 2);
262 __u
->__usi
= __src0_2
;
263 __u
= __extension__ ((void *) __u
+ 2);
265 __u
= __extension__ ((void *) __u
+ 1);
268 __u
->__ui
= __src0_4
;
269 __u
= __extension__ ((void *) __u
+ 4);
272 __u
->__ui
= __src0_4
;
273 __u
= __extension__ ((void *) __u
+ 4);
275 __u
= __extension__ ((void *) __u
+ 1);
278 __u
->__ui
= __src0_4
;
279 __u
= __extension__ ((void *) __u
+ 4);
280 __u
->__usi
= __src4_2
;
281 __u
= __extension__ ((void *) __u
+ 2);
284 __u
->__ui
= __src0_4
;
285 __u
= __extension__ ((void *) __u
+ 4);
286 __u
->__usi
= __src4_2
;
287 __u
= __extension__ ((void *) __u
+ 2);
289 __u
= __extension__ ((void *) __u
+ 1);
292 __u
->__ui
= __src0_4
;
293 __u
= __extension__ ((void *) __u
+ 4);
294 __u
->__ui
= __src4_4
;
295 __u
= __extension__ ((void *) __u
+ 4);
304 __old_mempcpy_small (void *__dest
, char __src1
,
305 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
306 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
307 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
308 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
312 __STRING2_COPY_ARR2 __sca2
;
313 __STRING2_COPY_ARR3 __sca3
;
314 __STRING2_COPY_ARR4 __sca4
;
315 __STRING2_COPY_ARR5 __sca5
;
316 __STRING2_COPY_ARR6 __sca6
;
317 __STRING2_COPY_ARR7 __sca7
;
318 __STRING2_COPY_ARR8 __sca8
;
320 switch ((unsigned int) __srclen
)
326 __extension__ __u
->__sca2
= __src2
;
329 __extension__ __u
->__sca3
= __src3
;
332 __extension__ __u
->__sca4
= __src4
;
335 __extension__ __u
->__sca5
= __src5
;
338 __extension__ __u
->__sca6
= __src6
;
341 __extension__ __u
->__sca7
= __src7
;
344 __extension__ __u
->__sca8
= __src8
;
347 return __extension__ ((void *) __u
+ __srclen
);
350 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
352 # if _STRING_INLINE_unaligned
354 __old_strcpy_small (char *__dest
,
355 __uint16_t __src0_2
, __uint16_t __src4_2
,
356 __uint32_t __src0_4
, __uint32_t __src4_4
,
363 } *__u
= (void *) __dest
;
364 switch ((unsigned int) __srclen
)
370 __u
->__usi
= __src0_2
;
373 __u
->__usi
= __src0_2
;
374 __u
= __extension__ ((void *) __u
+ 2);
378 __u
->__ui
= __src0_4
;
381 __u
->__ui
= __src0_4
;
382 __u
= __extension__ ((void *) __u
+ 4);
386 __u
->__ui
= __src0_4
;
387 __u
= __extension__ ((void *) __u
+ 4);
388 __u
->__usi
= __src4_2
;
391 __u
->__ui
= __src0_4
;
392 __u
= __extension__ ((void *) __u
+ 4);
393 __u
->__usi
= __src4_2
;
394 __u
= __extension__ ((void *) __u
+ 2);
398 __u
->__ui
= __src0_4
;
399 __u
= __extension__ ((void *) __u
+ 4);
400 __u
->__ui
= __src4_4
;
409 __old_strcpy_small (char *__dest
,
410 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
411 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
412 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
413 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
417 __STRING2_COPY_ARR2 __sca2
;
418 __STRING2_COPY_ARR3 __sca3
;
419 __STRING2_COPY_ARR4 __sca4
;
420 __STRING2_COPY_ARR5 __sca5
;
421 __STRING2_COPY_ARR6 __sca6
;
422 __STRING2_COPY_ARR7 __sca7
;
423 __STRING2_COPY_ARR8 __sca8
;
424 } *__u
= (void *) __dest
;
425 switch ((unsigned int) __srclen
)
431 __extension__ __u
->__sca2
= __src2
;
434 __extension__ __u
->__sca3
= __src3
;
437 __extension__ __u
->__sca4
= __src4
;
440 __extension__ __u
->__sca5
= __src5
;
443 __extension__ __u
->__sca6
= __src6
;
446 __extension__ __u
->__sca7
= __src7
;
449 __extension__ __u
->__sca8
= __src8
;
455 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
457 # if _STRING_INLINE_unaligned
459 __old_stpcpy_small (char *__dest
,
460 __uint16_t __src0_2
, __uint16_t __src4_2
,
461 __uint32_t __src0_4
, __uint32_t __src4_4
,
466 unsigned short int __usi
;
469 } *__u
= (void *) __dest
;
470 switch ((unsigned int) __srclen
)
476 __u
->__usi
= __src0_2
;
477 __u
= __extension__ ((void *) __u
+ 1);
480 __u
->__usi
= __src0_2
;
481 __u
= __extension__ ((void *) __u
+ 2);
485 __u
->__ui
= __src0_4
;
486 __u
= __extension__ ((void *) __u
+ 3);
489 __u
->__ui
= __src0_4
;
490 __u
= __extension__ ((void *) __u
+ 4);
494 __u
->__ui
= __src0_4
;
495 __u
= __extension__ ((void *) __u
+ 4);
496 __u
->__usi
= __src4_2
;
497 __u
= __extension__ ((void *) __u
+ 1);
500 __u
->__ui
= __src0_4
;
501 __u
= __extension__ ((void *) __u
+ 4);
502 __u
->__usi
= __src4_2
;
503 __u
= __extension__ ((void *) __u
+ 2);
507 __u
->__ui
= __src0_4
;
508 __u
= __extension__ ((void *) __u
+ 4);
509 __u
->__ui
= __src4_4
;
510 __u
= __extension__ ((void *) __u
+ 3);
519 __old_stpcpy_small (char *__dest
,
520 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
521 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
522 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
523 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
527 __STRING2_COPY_ARR2 __sca2
;
528 __STRING2_COPY_ARR3 __sca3
;
529 __STRING2_COPY_ARR4 __sca4
;
530 __STRING2_COPY_ARR5 __sca5
;
531 __STRING2_COPY_ARR6 __sca6
;
532 __STRING2_COPY_ARR7 __sca7
;
533 __STRING2_COPY_ARR8 __sca8
;
534 } *__u
= (void *) __dest
;
535 switch ((unsigned int) __srclen
)
541 __extension__ __u
->__sca2
= __src2
;
544 __extension__ __u
->__sca3
= __src3
;
547 __extension__ __u
->__sca4
= __src4
;
550 __extension__ __u
->__sca5
= __src5
;
553 __extension__ __u
->__sca6
= __src6
;
556 __extension__ __u
->__sca7
= __src7
;
559 __extension__ __u
->__sca8
= __src8
;
562 return __dest
+ __srclen
- 1;
565 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);