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_24)
39 /* The inline functions are not used from GLIBC 2.24 and forward, however
40 they are required to provide the symbols through string-inlines.c
41 (if inlining is not possible for compatibility reasons). */
43 __old_strcspn_c1 (const char *__s
, int __reject
)
46 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
50 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
53 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
56 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
57 && __s
[__result
] != __reject2
)
61 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
64 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
68 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
69 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
73 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
76 __old_strspn_c1 (const char *__s
, int __accept
)
79 /* Please note that __accept never can be '\0'. */
80 while (__s
[__result
] == __accept
)
84 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
87 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
90 /* Please note that __accept1 and __accept2 never can be '\0'. */
91 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
95 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
98 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
102 /* Please note that __accept1 to __accept3 never can be '\0'. */
103 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
104 || __s
[__result
] == __accept3
)
108 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
111 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
113 /* Please note that __accept1 and __accept2 never can be '\0'. */
114 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
116 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
118 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
121 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
123 /* Please note that __accept1 to __accept3 never can be '\0'. */
124 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
125 && *__s
!= __accept3
)
127 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
129 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
131 /* These are a few types we need for the optimizations if we cannot
132 use unaligned memory accesses. */
133 # define __STRING2_COPY_TYPE(N) \
134 typedef struct { unsigned char __arr[N]; } \
135 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
136 __STRING2_COPY_TYPE (2);
137 __STRING2_COPY_TYPE (3);
138 __STRING2_COPY_TYPE (4);
139 __STRING2_COPY_TYPE (5);
140 __STRING2_COPY_TYPE (6);
141 __STRING2_COPY_TYPE (7);
142 __STRING2_COPY_TYPE (8);
143 # undef __STRING2_COPY_TYPE
146 # if _STRING_INLINE_unaligned
148 __old_mempcpy_small (void *__dest1
,
149 char __src0_1
, char __src2_1
, char __src4_1
, char __src6_1
,
150 __uint16_t __src0_2
, __uint16_t __src4_2
,
151 __uint32_t __src0_4
, __uint32_t __src4_4
,
160 switch ((unsigned int) __srclen
)
164 __u
= __extension__ ((void *) __u
+ 1);
167 __u
->__usi
= __src0_2
;
168 __u
= __extension__ ((void *) __u
+ 2);
171 __u
->__usi
= __src0_2
;
172 __u
= __extension__ ((void *) __u
+ 2);
174 __u
= __extension__ ((void *) __u
+ 1);
177 __u
->__ui
= __src0_4
;
178 __u
= __extension__ ((void *) __u
+ 4);
181 __u
->__ui
= __src0_4
;
182 __u
= __extension__ ((void *) __u
+ 4);
184 __u
= __extension__ ((void *) __u
+ 1);
187 __u
->__ui
= __src0_4
;
188 __u
= __extension__ ((void *) __u
+ 4);
189 __u
->__usi
= __src4_2
;
190 __u
= __extension__ ((void *) __u
+ 2);
193 __u
->__ui
= __src0_4
;
194 __u
= __extension__ ((void *) __u
+ 4);
195 __u
->__usi
= __src4_2
;
196 __u
= __extension__ ((void *) __u
+ 2);
198 __u
= __extension__ ((void *) __u
+ 1);
201 __u
->__ui
= __src0_4
;
202 __u
= __extension__ ((void *) __u
+ 4);
203 __u
->__ui
= __src4_4
;
204 __u
= __extension__ ((void *) __u
+ 4);
213 __old_mempcpy_small (void *__dest
, char __src1
,
214 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
215 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
216 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
217 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
221 __STRING2_COPY_ARR2 __sca2
;
222 __STRING2_COPY_ARR3 __sca3
;
223 __STRING2_COPY_ARR4 __sca4
;
224 __STRING2_COPY_ARR5 __sca5
;
225 __STRING2_COPY_ARR6 __sca6
;
226 __STRING2_COPY_ARR7 __sca7
;
227 __STRING2_COPY_ARR8 __sca8
;
229 switch ((unsigned int) __srclen
)
235 __extension__ __u
->__sca2
= __src2
;
238 __extension__ __u
->__sca3
= __src3
;
241 __extension__ __u
->__sca4
= __src4
;
244 __extension__ __u
->__sca5
= __src5
;
247 __extension__ __u
->__sca6
= __src6
;
250 __extension__ __u
->__sca7
= __src7
;
253 __extension__ __u
->__sca8
= __src8
;
256 return __extension__ ((void *) __u
+ __srclen
);
259 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
261 # if _STRING_INLINE_unaligned
263 __old_strcpy_small (char *__dest
,
264 __uint16_t __src0_2
, __uint16_t __src4_2
,
265 __uint32_t __src0_4
, __uint32_t __src4_4
,
272 } *__u
= (void *) __dest
;
273 switch ((unsigned int) __srclen
)
279 __u
->__usi
= __src0_2
;
282 __u
->__usi
= __src0_2
;
283 __u
= __extension__ ((void *) __u
+ 2);
287 __u
->__ui
= __src0_4
;
290 __u
->__ui
= __src0_4
;
291 __u
= __extension__ ((void *) __u
+ 4);
295 __u
->__ui
= __src0_4
;
296 __u
= __extension__ ((void *) __u
+ 4);
297 __u
->__usi
= __src4_2
;
300 __u
->__ui
= __src0_4
;
301 __u
= __extension__ ((void *) __u
+ 4);
302 __u
->__usi
= __src4_2
;
303 __u
= __extension__ ((void *) __u
+ 2);
307 __u
->__ui
= __src0_4
;
308 __u
= __extension__ ((void *) __u
+ 4);
309 __u
->__ui
= __src4_4
;
318 __old_strcpy_small (char *__dest
,
319 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
320 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
321 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
322 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
326 __STRING2_COPY_ARR2 __sca2
;
327 __STRING2_COPY_ARR3 __sca3
;
328 __STRING2_COPY_ARR4 __sca4
;
329 __STRING2_COPY_ARR5 __sca5
;
330 __STRING2_COPY_ARR6 __sca6
;
331 __STRING2_COPY_ARR7 __sca7
;
332 __STRING2_COPY_ARR8 __sca8
;
333 } *__u
= (void *) __dest
;
334 switch ((unsigned int) __srclen
)
340 __extension__ __u
->__sca2
= __src2
;
343 __extension__ __u
->__sca3
= __src3
;
346 __extension__ __u
->__sca4
= __src4
;
349 __extension__ __u
->__sca5
= __src5
;
352 __extension__ __u
->__sca6
= __src6
;
355 __extension__ __u
->__sca7
= __src7
;
358 __extension__ __u
->__sca8
= __src8
;
364 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
366 # if _STRING_INLINE_unaligned
368 __old_stpcpy_small (char *__dest
,
369 __uint16_t __src0_2
, __uint16_t __src4_2
,
370 __uint32_t __src0_4
, __uint32_t __src4_4
,
375 unsigned short int __usi
;
378 } *__u
= (void *) __dest
;
379 switch ((unsigned int) __srclen
)
385 __u
->__usi
= __src0_2
;
386 __u
= __extension__ ((void *) __u
+ 1);
389 __u
->__usi
= __src0_2
;
390 __u
= __extension__ ((void *) __u
+ 2);
394 __u
->__ui
= __src0_4
;
395 __u
= __extension__ ((void *) __u
+ 3);
398 __u
->__ui
= __src0_4
;
399 __u
= __extension__ ((void *) __u
+ 4);
403 __u
->__ui
= __src0_4
;
404 __u
= __extension__ ((void *) __u
+ 4);
405 __u
->__usi
= __src4_2
;
406 __u
= __extension__ ((void *) __u
+ 1);
409 __u
->__ui
= __src0_4
;
410 __u
= __extension__ ((void *) __u
+ 4);
411 __u
->__usi
= __src4_2
;
412 __u
= __extension__ ((void *) __u
+ 2);
416 __u
->__ui
= __src0_4
;
417 __u
= __extension__ ((void *) __u
+ 4);
418 __u
->__ui
= __src4_4
;
419 __u
= __extension__ ((void *) __u
+ 3);
428 __old_stpcpy_small (char *__dest
,
429 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
430 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
431 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
432 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
436 __STRING2_COPY_ARR2 __sca2
;
437 __STRING2_COPY_ARR3 __sca3
;
438 __STRING2_COPY_ARR4 __sca4
;
439 __STRING2_COPY_ARR5 __sca5
;
440 __STRING2_COPY_ARR6 __sca6
;
441 __STRING2_COPY_ARR7 __sca7
;
442 __STRING2_COPY_ARR8 __sca8
;
443 } *__u
= (void *) __dest
;
444 switch ((unsigned int) __srclen
)
450 __extension__ __u
->__sca2
= __src2
;
453 __extension__ __u
->__sca3
= __src3
;
456 __extension__ __u
->__sca4
= __src4
;
459 __extension__ __u
->__sca5
= __src5
;
462 __extension__ __u
->__sca6
= __src6
;
465 __extension__ __u
->__sca7
= __src7
;
468 __extension__ __u
->__sca8
= __src8
;
471 return __dest
+ __srclen
- 1;
474 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);