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> and <bits/string2.h> declare some extern inline
19 functions. These functions are declared additionally here if
20 inlining is not possible. */
22 #undef __USE_STRING_INLINES
23 #define __USE_STRING_INLINES
24 #define _FORCE_INLINES
25 #define __STRING_INLINE /* empty */
33 #include <bits/string.h>
34 #include <bits/string2.h>
36 #include "shlib-compat.h"
38 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_25)
39 /* The inline functions are not used from GLIBC 2.25 and forward, however
40 they are required to provide the symbols through string-inlines.c
41 (if inlining is not possible for compatibility reasons). */
44 __old_strtok_r_1c (char *__s
, char __sep
, char **__nextp
)
65 compat_symbol (libc
, __old_strtok_r_1c
, __strtok_r_1c
, GLIBC_2_1_1
);
68 __old_strsep_1c (char **__s
, char __reject
)
70 char *__retval
= *__s
;
71 if (__retval
!= NULL
&& (*__s
= strchr (__retval
, __reject
)) != NULL
)
75 compat_symbol (libc
, __old_strsep_1c
, __strsep_1c
, GLIBC_2_1_1
);
78 __old_strsep_2c (char **__s
, char __reject1
, char __reject2
)
80 char *__retval
= *__s
;
83 char *__cp
= __retval
;
91 if (*__cp
== __reject1
|| *__cp
== __reject2
)
102 compat_symbol (libc
, __old_strsep_2c
, __strsep_2c
, GLIBC_2_1_1
);
105 __old_strsep_3c (char **__s
, char __reject1
, char __reject2
, char __reject3
)
107 char *__retval
= *__s
;
108 if (__retval
!= NULL
)
110 char *__cp
= __retval
;
118 if (*__cp
== __reject1
|| *__cp
== __reject2
|| *__cp
== __reject3
)
129 compat_symbol (libc
, __old_strsep_3c
, __strsep_3c
, GLIBC_2_1_1
);
132 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24)
133 /* The inline functions are not used from GLIBC 2.24 and forward, however
134 they are required to provide the symbols through string-inlines.c
135 (if inlining is not possible for compatibility reasons). */
137 __old_strcspn_c1 (const char *__s
, int __reject
)
140 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
144 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
147 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
150 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
151 && __s
[__result
] != __reject2
)
155 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
158 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
162 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
163 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
167 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
170 __old_strspn_c1 (const char *__s
, int __accept
)
173 /* Please note that __accept never can be '\0'. */
174 while (__s
[__result
] == __accept
)
178 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
181 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
184 /* Please note that __accept1 and __accept2 never can be '\0'. */
185 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
189 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
192 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
196 /* Please note that __accept1 to __accept3 never can be '\0'. */
197 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
198 || __s
[__result
] == __accept3
)
202 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
205 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
207 /* Please note that __accept1 and __accept2 never can be '\0'. */
208 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
210 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
212 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
215 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
217 /* Please note that __accept1 to __accept3 never can be '\0'. */
218 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
219 && *__s
!= __accept3
)
221 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
223 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
225 /* These are a few types we need for the optimizations if we cannot
226 use unaligned memory accesses. */
227 # define __STRING2_COPY_TYPE(N) \
228 typedef struct { unsigned char __arr[N]; } \
229 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
230 __STRING2_COPY_TYPE (2);
231 __STRING2_COPY_TYPE (3);
232 __STRING2_COPY_TYPE (4);
233 __STRING2_COPY_TYPE (5);
234 __STRING2_COPY_TYPE (6);
235 __STRING2_COPY_TYPE (7);
236 __STRING2_COPY_TYPE (8);
237 # undef __STRING2_COPY_TYPE
240 # if _STRING_INLINE_unaligned
242 __old_mempcpy_small (void *__dest1
,
243 char __src0_1
, char __src2_1
, char __src4_1
, char __src6_1
,
244 __uint16_t __src0_2
, __uint16_t __src4_2
,
245 __uint32_t __src0_4
, __uint32_t __src4_4
,
254 switch ((unsigned int) __srclen
)
258 __u
= __extension__ ((void *) __u
+ 1);
261 __u
->__usi
= __src0_2
;
262 __u
= __extension__ ((void *) __u
+ 2);
265 __u
->__usi
= __src0_2
;
266 __u
= __extension__ ((void *) __u
+ 2);
268 __u
= __extension__ ((void *) __u
+ 1);
271 __u
->__ui
= __src0_4
;
272 __u
= __extension__ ((void *) __u
+ 4);
275 __u
->__ui
= __src0_4
;
276 __u
= __extension__ ((void *) __u
+ 4);
278 __u
= __extension__ ((void *) __u
+ 1);
281 __u
->__ui
= __src0_4
;
282 __u
= __extension__ ((void *) __u
+ 4);
283 __u
->__usi
= __src4_2
;
284 __u
= __extension__ ((void *) __u
+ 2);
287 __u
->__ui
= __src0_4
;
288 __u
= __extension__ ((void *) __u
+ 4);
289 __u
->__usi
= __src4_2
;
290 __u
= __extension__ ((void *) __u
+ 2);
292 __u
= __extension__ ((void *) __u
+ 1);
295 __u
->__ui
= __src0_4
;
296 __u
= __extension__ ((void *) __u
+ 4);
297 __u
->__ui
= __src4_4
;
298 __u
= __extension__ ((void *) __u
+ 4);
307 __old_mempcpy_small (void *__dest
, char __src1
,
308 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
309 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
310 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
311 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
315 __STRING2_COPY_ARR2 __sca2
;
316 __STRING2_COPY_ARR3 __sca3
;
317 __STRING2_COPY_ARR4 __sca4
;
318 __STRING2_COPY_ARR5 __sca5
;
319 __STRING2_COPY_ARR6 __sca6
;
320 __STRING2_COPY_ARR7 __sca7
;
321 __STRING2_COPY_ARR8 __sca8
;
323 switch ((unsigned int) __srclen
)
329 __extension__ __u
->__sca2
= __src2
;
332 __extension__ __u
->__sca3
= __src3
;
335 __extension__ __u
->__sca4
= __src4
;
338 __extension__ __u
->__sca5
= __src5
;
341 __extension__ __u
->__sca6
= __src6
;
344 __extension__ __u
->__sca7
= __src7
;
347 __extension__ __u
->__sca8
= __src8
;
350 return __extension__ ((void *) __u
+ __srclen
);
353 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
355 # if _STRING_INLINE_unaligned
357 __old_strcpy_small (char *__dest
,
358 __uint16_t __src0_2
, __uint16_t __src4_2
,
359 __uint32_t __src0_4
, __uint32_t __src4_4
,
366 } *__u
= (void *) __dest
;
367 switch ((unsigned int) __srclen
)
373 __u
->__usi
= __src0_2
;
376 __u
->__usi
= __src0_2
;
377 __u
= __extension__ ((void *) __u
+ 2);
381 __u
->__ui
= __src0_4
;
384 __u
->__ui
= __src0_4
;
385 __u
= __extension__ ((void *) __u
+ 4);
389 __u
->__ui
= __src0_4
;
390 __u
= __extension__ ((void *) __u
+ 4);
391 __u
->__usi
= __src4_2
;
394 __u
->__ui
= __src0_4
;
395 __u
= __extension__ ((void *) __u
+ 4);
396 __u
->__usi
= __src4_2
;
397 __u
= __extension__ ((void *) __u
+ 2);
401 __u
->__ui
= __src0_4
;
402 __u
= __extension__ ((void *) __u
+ 4);
403 __u
->__ui
= __src4_4
;
412 __old_strcpy_small (char *__dest
,
413 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
414 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
415 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
416 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
420 __STRING2_COPY_ARR2 __sca2
;
421 __STRING2_COPY_ARR3 __sca3
;
422 __STRING2_COPY_ARR4 __sca4
;
423 __STRING2_COPY_ARR5 __sca5
;
424 __STRING2_COPY_ARR6 __sca6
;
425 __STRING2_COPY_ARR7 __sca7
;
426 __STRING2_COPY_ARR8 __sca8
;
427 } *__u
= (void *) __dest
;
428 switch ((unsigned int) __srclen
)
434 __extension__ __u
->__sca2
= __src2
;
437 __extension__ __u
->__sca3
= __src3
;
440 __extension__ __u
->__sca4
= __src4
;
443 __extension__ __u
->__sca5
= __src5
;
446 __extension__ __u
->__sca6
= __src6
;
449 __extension__ __u
->__sca7
= __src7
;
452 __extension__ __u
->__sca8
= __src8
;
458 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
460 # if _STRING_INLINE_unaligned
462 __old_stpcpy_small (char *__dest
,
463 __uint16_t __src0_2
, __uint16_t __src4_2
,
464 __uint32_t __src0_4
, __uint32_t __src4_4
,
469 unsigned short int __usi
;
472 } *__u
= (void *) __dest
;
473 switch ((unsigned int) __srclen
)
479 __u
->__usi
= __src0_2
;
480 __u
= __extension__ ((void *) __u
+ 1);
483 __u
->__usi
= __src0_2
;
484 __u
= __extension__ ((void *) __u
+ 2);
488 __u
->__ui
= __src0_4
;
489 __u
= __extension__ ((void *) __u
+ 3);
492 __u
->__ui
= __src0_4
;
493 __u
= __extension__ ((void *) __u
+ 4);
497 __u
->__ui
= __src0_4
;
498 __u
= __extension__ ((void *) __u
+ 4);
499 __u
->__usi
= __src4_2
;
500 __u
= __extension__ ((void *) __u
+ 1);
503 __u
->__ui
= __src0_4
;
504 __u
= __extension__ ((void *) __u
+ 4);
505 __u
->__usi
= __src4_2
;
506 __u
= __extension__ ((void *) __u
+ 2);
510 __u
->__ui
= __src0_4
;
511 __u
= __extension__ ((void *) __u
+ 4);
512 __u
->__ui
= __src4_4
;
513 __u
= __extension__ ((void *) __u
+ 3);
522 __old_stpcpy_small (char *__dest
,
523 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
524 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
525 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
526 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
530 __STRING2_COPY_ARR2 __sca2
;
531 __STRING2_COPY_ARR3 __sca3
;
532 __STRING2_COPY_ARR4 __sca4
;
533 __STRING2_COPY_ARR5 __sca5
;
534 __STRING2_COPY_ARR6 __sca6
;
535 __STRING2_COPY_ARR7 __sca7
;
536 __STRING2_COPY_ARR8 __sca8
;
537 } *__u
= (void *) __dest
;
538 switch ((unsigned int) __srclen
)
544 __extension__ __u
->__sca2
= __src2
;
547 __extension__ __u
->__sca3
= __src3
;
550 __extension__ __u
->__sca4
= __src4
;
553 __extension__ __u
->__sca5
= __src5
;
556 __extension__ __u
->__sca6
= __src6
;
559 __extension__ __u
->__sca7
= __src7
;
562 __extension__ __u
->__sca8
= __src8
;
565 return __dest
+ __srclen
- 1;
568 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);