1 /* Copyright (C) 1999-2016 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 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24)
69 /* The inline functions are not used from GLIBC 2.24 and forward, however
70 they are required to provide the symbols through string-inlines.c
71 (if inlining is not possible for compatibility reasons). */
73 __old_strcspn_c1 (const char *__s
, int __reject
)
76 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
80 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
83 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
86 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
87 && __s
[__result
] != __reject2
)
91 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
94 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
98 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
99 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
103 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
106 __old_strspn_c1 (const char *__s
, int __accept
)
109 /* Please note that __accept never can be '\0'. */
110 while (__s
[__result
] == __accept
)
114 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
117 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
120 /* Please note that __accept1 and __accept2 never can be '\0'. */
121 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
125 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
128 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
132 /* Please note that __accept1 to __accept3 never can be '\0'. */
133 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
134 || __s
[__result
] == __accept3
)
138 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
141 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
143 /* Please note that __accept1 and __accept2 never can be '\0'. */
144 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
146 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
148 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
151 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
153 /* Please note that __accept1 to __accept3 never can be '\0'. */
154 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
155 && *__s
!= __accept3
)
157 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
159 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
161 /* These are a few types we need for the optimizations if we cannot
162 use unaligned memory accesses. */
163 # define __STRING2_COPY_TYPE(N) \
164 typedef struct { unsigned char __arr[N]; } \
165 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
166 __STRING2_COPY_TYPE (2);
167 __STRING2_COPY_TYPE (3);
168 __STRING2_COPY_TYPE (4);
169 __STRING2_COPY_TYPE (5);
170 __STRING2_COPY_TYPE (6);
171 __STRING2_COPY_TYPE (7);
172 __STRING2_COPY_TYPE (8);
173 # undef __STRING2_COPY_TYPE
176 # if _STRING_INLINE_unaligned
178 __old_mempcpy_small (void *__dest1
,
179 char __src0_1
, char __src2_1
, char __src4_1
, char __src6_1
,
180 __uint16_t __src0_2
, __uint16_t __src4_2
,
181 __uint32_t __src0_4
, __uint32_t __src4_4
,
190 switch ((unsigned int) __srclen
)
194 __u
= __extension__ ((void *) __u
+ 1);
197 __u
->__usi
= __src0_2
;
198 __u
= __extension__ ((void *) __u
+ 2);
201 __u
->__usi
= __src0_2
;
202 __u
= __extension__ ((void *) __u
+ 2);
204 __u
= __extension__ ((void *) __u
+ 1);
207 __u
->__ui
= __src0_4
;
208 __u
= __extension__ ((void *) __u
+ 4);
211 __u
->__ui
= __src0_4
;
212 __u
= __extension__ ((void *) __u
+ 4);
214 __u
= __extension__ ((void *) __u
+ 1);
217 __u
->__ui
= __src0_4
;
218 __u
= __extension__ ((void *) __u
+ 4);
219 __u
->__usi
= __src4_2
;
220 __u
= __extension__ ((void *) __u
+ 2);
223 __u
->__ui
= __src0_4
;
224 __u
= __extension__ ((void *) __u
+ 4);
225 __u
->__usi
= __src4_2
;
226 __u
= __extension__ ((void *) __u
+ 2);
228 __u
= __extension__ ((void *) __u
+ 1);
231 __u
->__ui
= __src0_4
;
232 __u
= __extension__ ((void *) __u
+ 4);
233 __u
->__ui
= __src4_4
;
234 __u
= __extension__ ((void *) __u
+ 4);
243 __old_mempcpy_small (void *__dest
, char __src1
,
244 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
245 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
246 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
247 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
251 __STRING2_COPY_ARR2 __sca2
;
252 __STRING2_COPY_ARR3 __sca3
;
253 __STRING2_COPY_ARR4 __sca4
;
254 __STRING2_COPY_ARR5 __sca5
;
255 __STRING2_COPY_ARR6 __sca6
;
256 __STRING2_COPY_ARR7 __sca7
;
257 __STRING2_COPY_ARR8 __sca8
;
259 switch ((unsigned int) __srclen
)
265 __extension__ __u
->__sca2
= __src2
;
268 __extension__ __u
->__sca3
= __src3
;
271 __extension__ __u
->__sca4
= __src4
;
274 __extension__ __u
->__sca5
= __src5
;
277 __extension__ __u
->__sca6
= __src6
;
280 __extension__ __u
->__sca7
= __src7
;
283 __extension__ __u
->__sca8
= __src8
;
286 return __extension__ ((void *) __u
+ __srclen
);
289 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
291 # if _STRING_INLINE_unaligned
293 __old_strcpy_small (char *__dest
,
294 __uint16_t __src0_2
, __uint16_t __src4_2
,
295 __uint32_t __src0_4
, __uint32_t __src4_4
,
302 } *__u
= (void *) __dest
;
303 switch ((unsigned int) __srclen
)
309 __u
->__usi
= __src0_2
;
312 __u
->__usi
= __src0_2
;
313 __u
= __extension__ ((void *) __u
+ 2);
317 __u
->__ui
= __src0_4
;
320 __u
->__ui
= __src0_4
;
321 __u
= __extension__ ((void *) __u
+ 4);
325 __u
->__ui
= __src0_4
;
326 __u
= __extension__ ((void *) __u
+ 4);
327 __u
->__usi
= __src4_2
;
330 __u
->__ui
= __src0_4
;
331 __u
= __extension__ ((void *) __u
+ 4);
332 __u
->__usi
= __src4_2
;
333 __u
= __extension__ ((void *) __u
+ 2);
337 __u
->__ui
= __src0_4
;
338 __u
= __extension__ ((void *) __u
+ 4);
339 __u
->__ui
= __src4_4
;
348 __old_strcpy_small (char *__dest
,
349 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
350 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
351 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
352 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
356 __STRING2_COPY_ARR2 __sca2
;
357 __STRING2_COPY_ARR3 __sca3
;
358 __STRING2_COPY_ARR4 __sca4
;
359 __STRING2_COPY_ARR5 __sca5
;
360 __STRING2_COPY_ARR6 __sca6
;
361 __STRING2_COPY_ARR7 __sca7
;
362 __STRING2_COPY_ARR8 __sca8
;
363 } *__u
= (void *) __dest
;
364 switch ((unsigned int) __srclen
)
370 __extension__ __u
->__sca2
= __src2
;
373 __extension__ __u
->__sca3
= __src3
;
376 __extension__ __u
->__sca4
= __src4
;
379 __extension__ __u
->__sca5
= __src5
;
382 __extension__ __u
->__sca6
= __src6
;
385 __extension__ __u
->__sca7
= __src7
;
388 __extension__ __u
->__sca8
= __src8
;
394 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
396 # if _STRING_INLINE_unaligned
398 __old_stpcpy_small (char *__dest
,
399 __uint16_t __src0_2
, __uint16_t __src4_2
,
400 __uint32_t __src0_4
, __uint32_t __src4_4
,
405 unsigned short int __usi
;
408 } *__u
= (void *) __dest
;
409 switch ((unsigned int) __srclen
)
415 __u
->__usi
= __src0_2
;
416 __u
= __extension__ ((void *) __u
+ 1);
419 __u
->__usi
= __src0_2
;
420 __u
= __extension__ ((void *) __u
+ 2);
424 __u
->__ui
= __src0_4
;
425 __u
= __extension__ ((void *) __u
+ 3);
428 __u
->__ui
= __src0_4
;
429 __u
= __extension__ ((void *) __u
+ 4);
433 __u
->__ui
= __src0_4
;
434 __u
= __extension__ ((void *) __u
+ 4);
435 __u
->__usi
= __src4_2
;
436 __u
= __extension__ ((void *) __u
+ 1);
439 __u
->__ui
= __src0_4
;
440 __u
= __extension__ ((void *) __u
+ 4);
441 __u
->__usi
= __src4_2
;
442 __u
= __extension__ ((void *) __u
+ 2);
446 __u
->__ui
= __src0_4
;
447 __u
= __extension__ ((void *) __u
+ 4);
448 __u
->__ui
= __src4_4
;
449 __u
= __extension__ ((void *) __u
+ 3);
458 __old_stpcpy_small (char *__dest
,
459 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
460 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
461 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
462 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
466 __STRING2_COPY_ARR2 __sca2
;
467 __STRING2_COPY_ARR3 __sca3
;
468 __STRING2_COPY_ARR4 __sca4
;
469 __STRING2_COPY_ARR5 __sca5
;
470 __STRING2_COPY_ARR6 __sca6
;
471 __STRING2_COPY_ARR7 __sca7
;
472 __STRING2_COPY_ARR8 __sca8
;
473 } *__u
= (void *) __dest
;
474 switch ((unsigned int) __srclen
)
480 __extension__ __u
->__sca2
= __src2
;
483 __extension__ __u
->__sca3
= __src3
;
486 __extension__ __u
->__sca4
= __src4
;
489 __extension__ __u
->__sca5
= __src5
;
492 __extension__ __u
->__sca6
= __src6
;
495 __extension__ __u
->__sca7
= __src7
;
498 __extension__ __u
->__sca8
= __src8
;
501 return __dest
+ __srclen
- 1;
504 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);