Use PTR_ALIGN_DOWN on strcspn and strspn
[glibc.git] / string / string-inlines.c
blob06483760c369e5635382a3feb99967966fa1a6a2
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 */
26 #define __NO_INLINE__
28 #include <string.h>
29 #undef index
30 #undef rindex
32 #undef __NO_INLINE__
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). */
42 size_t
43 __old_strcspn_c1 (const char *__s, int __reject)
45 size_t __result = 0;
46 while (__s[__result] != '\0' && __s[__result] != __reject)
47 ++__result;
48 return __result;
50 compat_symbol (libc, __old_strcspn_c1, __strcspn_c1, GLIBC_2_1_1);
52 size_t
53 __old_strcspn_c2 (const char *__s, int __reject1, int __reject2)
55 size_t __result = 0;
56 while (__s[__result] != '\0' && __s[__result] != __reject1
57 && __s[__result] != __reject2)
58 ++__result;
59 return __result;
61 compat_symbol (libc, __old_strcspn_c2, __strcspn_c2, GLIBC_2_1_1);
63 size_t
64 __old_strcspn_c3 (const char *__s, int __reject1, int __reject2,
65 int __reject3)
67 size_t __result = 0;
68 while (__s[__result] != '\0' && __s[__result] != __reject1
69 && __s[__result] != __reject2 && __s[__result] != __reject3)
70 ++__result;
71 return __result;
73 compat_symbol (libc, __old_strcspn_c3, __strcspn_c3, GLIBC_2_1_1);
75 size_t
76 __old_strspn_c1 (const char *__s, int __accept)
78 size_t __result = 0;
79 /* Please note that __accept never can be '\0'. */
80 while (__s[__result] == __accept)
81 ++__result;
82 return __result;
84 compat_symbol (libc, __old_strspn_c1, __strspn_c1, GLIBC_2_1_1);
86 size_t
87 __old_strspn_c2 (const char *__s, int __accept1, int __accept2)
89 size_t __result = 0;
90 /* Please note that __accept1 and __accept2 never can be '\0'. */
91 while (__s[__result] == __accept1 || __s[__result] == __accept2)
92 ++__result;
93 return __result;
95 compat_symbol (libc, __old_strspn_c2, __strspn_c2, GLIBC_2_1_1);
97 size_t
98 __old_strspn_c3 (const char *__s, int __accept1, int __accept2,
99 int __accept3)
101 size_t __result = 0;
102 /* Please note that __accept1 to __accept3 never can be '\0'. */
103 while (__s[__result] == __accept1 || __s[__result] == __accept2
104 || __s[__result] == __accept3)
105 ++__result;
106 return __result;
108 compat_symbol (libc, __old_strspn_c3, __strspn_c3, GLIBC_2_1_1);
110 char *
111 __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)
115 ++__s;
116 return *__s == '\0' ? NULL : (char *) (size_t) __s;
118 compat_symbol (libc, __old_strpbrk_c2, __strpbrk_c2, GLIBC_2_1_1);
120 char *
121 __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)
126 ++__s;
127 return *__s == '\0' ? NULL : (char *) (size_t) __s;
129 compat_symbol (libc, __old_strpbrk_c3, __strpbrk_c3, GLIBC_2_1_1);
131 #endif