1 /* Copyright (C) 1999-2022 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 <https://www.gnu.org/licenses/>. */
18 /* This file contains compatibility definitions of functions that were
19 formerly defined as "extern inline" in string.h; it's conceivable
20 that old binaries contain references to them. */
22 #define __NO_STRING_INLINES
25 #include "shlib-compat.h"
27 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_25)
28 /* These functions were removed from string.h in glibc 2.25. */
31 __old_strtok_r_1c (char *__s
, char __sep
, char **__nextp
)
52 compat_symbol (libc
, __old_strtok_r_1c
, __strtok_r_1c
, GLIBC_2_1_1
);
55 __old_strsep_1c (char **__s
, char __reject
)
57 char *__retval
= *__s
;
58 if (__retval
!= NULL
&& (*__s
= strchr (__retval
, __reject
)) != NULL
)
62 compat_symbol (libc
, __old_strsep_1c
, __strsep_1c
, GLIBC_2_1_1
);
65 __old_strsep_2c (char **__s
, char __reject1
, char __reject2
)
67 char *__retval
= *__s
;
70 char *__cp
= __retval
;
78 if (*__cp
== __reject1
|| *__cp
== __reject2
)
89 compat_symbol (libc
, __old_strsep_2c
, __strsep_2c
, GLIBC_2_1_1
);
92 __old_strsep_3c (char **__s
, char __reject1
, char __reject2
, char __reject3
)
94 char *__retval
= *__s
;
97 char *__cp
= __retval
;
105 if (*__cp
== __reject1
|| *__cp
== __reject2
|| *__cp
== __reject3
)
116 compat_symbol (libc
, __old_strsep_3c
, __strsep_3c
, GLIBC_2_1_1
);
119 #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24)
120 /* These functions were removed from string.h in glibc 2.24. */
123 __old_strcspn_c1 (const char *__s
, int __reject
)
126 while (__s
[__result
] != '\0' && __s
[__result
] != __reject
)
130 compat_symbol (libc
, __old_strcspn_c1
, __strcspn_c1
, GLIBC_2_1_1
);
133 __old_strcspn_c2 (const char *__s
, int __reject1
, int __reject2
)
136 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
137 && __s
[__result
] != __reject2
)
141 compat_symbol (libc
, __old_strcspn_c2
, __strcspn_c2
, GLIBC_2_1_1
);
144 __old_strcspn_c3 (const char *__s
, int __reject1
, int __reject2
,
148 while (__s
[__result
] != '\0' && __s
[__result
] != __reject1
149 && __s
[__result
] != __reject2
&& __s
[__result
] != __reject3
)
153 compat_symbol (libc
, __old_strcspn_c3
, __strcspn_c3
, GLIBC_2_1_1
);
156 __old_strspn_c1 (const char *__s
, int __accept
)
159 /* Please note that __accept never can be '\0'. */
160 while (__s
[__result
] == __accept
)
164 compat_symbol (libc
, __old_strspn_c1
, __strspn_c1
, GLIBC_2_1_1
);
167 __old_strspn_c2 (const char *__s
, int __accept1
, int __accept2
)
170 /* Please note that __accept1 and __accept2 never can be '\0'. */
171 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
)
175 compat_symbol (libc
, __old_strspn_c2
, __strspn_c2
, GLIBC_2_1_1
);
178 __old_strspn_c3 (const char *__s
, int __accept1
, int __accept2
,
182 /* Please note that __accept1 to __accept3 never can be '\0'. */
183 while (__s
[__result
] == __accept1
|| __s
[__result
] == __accept2
184 || __s
[__result
] == __accept3
)
188 compat_symbol (libc
, __old_strspn_c3
, __strspn_c3
, GLIBC_2_1_1
);
191 __old_strpbrk_c2 (const char *__s
, int __accept1
, int __accept2
)
193 /* Please note that __accept1 and __accept2 never can be '\0'. */
194 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
)
196 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
198 compat_symbol (libc
, __old_strpbrk_c2
, __strpbrk_c2
, GLIBC_2_1_1
);
201 __old_strpbrk_c3 (const char *__s
, int __accept1
, int __accept2
, int __accept3
)
203 /* Please note that __accept1 to __accept3 never can be '\0'. */
204 while (*__s
!= '\0' && *__s
!= __accept1
&& *__s
!= __accept2
205 && *__s
!= __accept3
)
207 return *__s
== '\0' ? NULL
: (char *) (size_t) __s
;
209 compat_symbol (libc
, __old_strpbrk_c3
, __strpbrk_c3
, GLIBC_2_1_1
);
211 # if defined __mc68020__ || defined __s390__ || defined __i386__
212 # define _STRING_INLINE_unaligned 1
214 # define _STRING_INLINE_unaligned 0
215 /* These are a few types we need for the optimizations if we cannot
216 use unaligned memory accesses. */
217 # define __STRING2_COPY_TYPE(N) \
218 typedef struct { unsigned char __arr[N]; } \
219 __attribute__ ((__packed__)) __STRING2_COPY_ARR##N
220 __STRING2_COPY_TYPE (2);
221 __STRING2_COPY_TYPE (3);
222 __STRING2_COPY_TYPE (4);
223 __STRING2_COPY_TYPE (5);
224 __STRING2_COPY_TYPE (6);
225 __STRING2_COPY_TYPE (7);
226 __STRING2_COPY_TYPE (8);
227 # undef __STRING2_COPY_TYPE
230 # if _STRING_INLINE_unaligned
232 __old_mempcpy_small (void *__dest1
,
233 char __src0_1
, char __src2_1
, char __src4_1
, char __src6_1
,
234 __uint16_t __src0_2
, __uint16_t __src4_2
,
235 __uint32_t __src0_4
, __uint32_t __src4_4
,
244 switch ((unsigned int) __srclen
)
248 __u
= __extension__ ((void *) __u
+ 1);
251 __u
->__usi
= __src0_2
;
252 __u
= __extension__ ((void *) __u
+ 2);
255 __u
->__usi
= __src0_2
;
256 __u
= __extension__ ((void *) __u
+ 2);
258 __u
= __extension__ ((void *) __u
+ 1);
261 __u
->__ui
= __src0_4
;
262 __u
= __extension__ ((void *) __u
+ 4);
265 __u
->__ui
= __src0_4
;
266 __u
= __extension__ ((void *) __u
+ 4);
268 __u
= __extension__ ((void *) __u
+ 1);
271 __u
->__ui
= __src0_4
;
272 __u
= __extension__ ((void *) __u
+ 4);
273 __u
->__usi
= __src4_2
;
274 __u
= __extension__ ((void *) __u
+ 2);
277 __u
->__ui
= __src0_4
;
278 __u
= __extension__ ((void *) __u
+ 4);
279 __u
->__usi
= __src4_2
;
280 __u
= __extension__ ((void *) __u
+ 2);
282 __u
= __extension__ ((void *) __u
+ 1);
285 __u
->__ui
= __src0_4
;
286 __u
= __extension__ ((void *) __u
+ 4);
287 __u
->__ui
= __src4_4
;
288 __u
= __extension__ ((void *) __u
+ 4);
297 __old_mempcpy_small (void *__dest
, char __src1
,
298 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
299 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
300 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
301 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
305 __STRING2_COPY_ARR2 __sca2
;
306 __STRING2_COPY_ARR3 __sca3
;
307 __STRING2_COPY_ARR4 __sca4
;
308 __STRING2_COPY_ARR5 __sca5
;
309 __STRING2_COPY_ARR6 __sca6
;
310 __STRING2_COPY_ARR7 __sca7
;
311 __STRING2_COPY_ARR8 __sca8
;
313 switch ((unsigned int) __srclen
)
319 __extension__ __u
->__sca2
= __src2
;
322 __extension__ __u
->__sca3
= __src3
;
325 __extension__ __u
->__sca4
= __src4
;
328 __extension__ __u
->__sca5
= __src5
;
331 __extension__ __u
->__sca6
= __src6
;
334 __extension__ __u
->__sca7
= __src7
;
337 __extension__ __u
->__sca8
= __src8
;
340 return __extension__ ((void *) __u
+ __srclen
);
343 compat_symbol (libc
, __old_mempcpy_small
, __mempcpy_small
, GLIBC_2_1_1
);
345 # if _STRING_INLINE_unaligned
347 __old_strcpy_small (char *__dest
,
348 __uint16_t __src0_2
, __uint16_t __src4_2
,
349 __uint32_t __src0_4
, __uint32_t __src4_4
,
356 } *__u
= (void *) __dest
;
357 switch ((unsigned int) __srclen
)
363 __u
->__usi
= __src0_2
;
366 __u
->__usi
= __src0_2
;
367 __u
= __extension__ ((void *) __u
+ 2);
371 __u
->__ui
= __src0_4
;
374 __u
->__ui
= __src0_4
;
375 __u
= __extension__ ((void *) __u
+ 4);
379 __u
->__ui
= __src0_4
;
380 __u
= __extension__ ((void *) __u
+ 4);
381 __u
->__usi
= __src4_2
;
384 __u
->__ui
= __src0_4
;
385 __u
= __extension__ ((void *) __u
+ 4);
386 __u
->__usi
= __src4_2
;
387 __u
= __extension__ ((void *) __u
+ 2);
391 __u
->__ui
= __src0_4
;
392 __u
= __extension__ ((void *) __u
+ 4);
393 __u
->__ui
= __src4_4
;
402 __old_strcpy_small (char *__dest
,
403 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
404 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
405 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
406 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
410 __STRING2_COPY_ARR2 __sca2
;
411 __STRING2_COPY_ARR3 __sca3
;
412 __STRING2_COPY_ARR4 __sca4
;
413 __STRING2_COPY_ARR5 __sca5
;
414 __STRING2_COPY_ARR6 __sca6
;
415 __STRING2_COPY_ARR7 __sca7
;
416 __STRING2_COPY_ARR8 __sca8
;
417 } *__u
= (void *) __dest
;
418 switch ((unsigned int) __srclen
)
424 __extension__ __u
->__sca2
= __src2
;
427 __extension__ __u
->__sca3
= __src3
;
430 __extension__ __u
->__sca4
= __src4
;
433 __extension__ __u
->__sca5
= __src5
;
436 __extension__ __u
->__sca6
= __src6
;
439 __extension__ __u
->__sca7
= __src7
;
442 __extension__ __u
->__sca8
= __src8
;
448 compat_symbol (libc
, __old_strcpy_small
, __strcpy_small
, GLIBC_2_1_1
);
450 # if _STRING_INLINE_unaligned
452 __old_stpcpy_small (char *__dest
,
453 __uint16_t __src0_2
, __uint16_t __src4_2
,
454 __uint32_t __src0_4
, __uint32_t __src4_4
,
459 unsigned short int __usi
;
462 } *__u
= (void *) __dest
;
463 switch ((unsigned int) __srclen
)
469 __u
->__usi
= __src0_2
;
470 __u
= __extension__ ((void *) __u
+ 1);
473 __u
->__usi
= __src0_2
;
474 __u
= __extension__ ((void *) __u
+ 2);
478 __u
->__ui
= __src0_4
;
479 __u
= __extension__ ((void *) __u
+ 3);
482 __u
->__ui
= __src0_4
;
483 __u
= __extension__ ((void *) __u
+ 4);
487 __u
->__ui
= __src0_4
;
488 __u
= __extension__ ((void *) __u
+ 4);
489 __u
->__usi
= __src4_2
;
490 __u
= __extension__ ((void *) __u
+ 1);
493 __u
->__ui
= __src0_4
;
494 __u
= __extension__ ((void *) __u
+ 4);
495 __u
->__usi
= __src4_2
;
496 __u
= __extension__ ((void *) __u
+ 2);
500 __u
->__ui
= __src0_4
;
501 __u
= __extension__ ((void *) __u
+ 4);
502 __u
->__ui
= __src4_4
;
503 __u
= __extension__ ((void *) __u
+ 3);
512 __old_stpcpy_small (char *__dest
,
513 __STRING2_COPY_ARR2 __src2
, __STRING2_COPY_ARR3 __src3
,
514 __STRING2_COPY_ARR4 __src4
, __STRING2_COPY_ARR5 __src5
,
515 __STRING2_COPY_ARR6 __src6
, __STRING2_COPY_ARR7 __src7
,
516 __STRING2_COPY_ARR8 __src8
, size_t __srclen
)
520 __STRING2_COPY_ARR2 __sca2
;
521 __STRING2_COPY_ARR3 __sca3
;
522 __STRING2_COPY_ARR4 __sca4
;
523 __STRING2_COPY_ARR5 __sca5
;
524 __STRING2_COPY_ARR6 __sca6
;
525 __STRING2_COPY_ARR7 __sca7
;
526 __STRING2_COPY_ARR8 __sca8
;
527 } *__u
= (void *) __dest
;
528 switch ((unsigned int) __srclen
)
534 __extension__ __u
->__sca2
= __src2
;
537 __extension__ __u
->__sca3
= __src3
;
540 __extension__ __u
->__sca4
= __src4
;
543 __extension__ __u
->__sca5
= __src5
;
546 __extension__ __u
->__sca6
= __src6
;
549 __extension__ __u
->__sca7
= __src7
;
552 __extension__ __u
->__sca8
= __src8
;
555 return __dest
+ __srclen
- 1;
558 compat_symbol (libc
, __old_stpcpy_small
, __stpcpy_small
, GLIBC_2_1_1
);