George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _STRING_H |
| 30 | #error "Never include this file directly; instead, include <string.h>" |
| 31 | #endif |
| 32 | |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 33 | void* __memchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23); |
| 34 | void* __memrchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23); |
| 35 | char* __stpncpy_chk2(char*, const char*, size_t, size_t, size_t) __INTRODUCED_IN(21); |
| 36 | char* __strncpy_chk2(char*, const char*, size_t, size_t, size_t) __INTRODUCED_IN(21); |
| 37 | size_t __strlcpy_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17); |
| 38 | size_t __strlcat_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 39 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 40 | #if defined(__BIONIC_FORTIFY) |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 41 | extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr); |
| 42 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 43 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 44 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 45 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 46 | void* memcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 47 | __overloadable { |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 48 | size_t bos_dst = __bos0(dst); |
| 49 | if (__bos_trivially_not_lt(bos_dst, copy_amount)) { |
| 50 | return __builtin_memcpy(dst, src, copy_amount); |
| 51 | } |
| 52 | return __builtin___memcpy_chk(dst, src, copy_amount, bos_dst); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 53 | } |
| 54 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 55 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 56 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 57 | void* memmove(void* const dst __pass_object_size0, const void* src, size_t len) __overloadable { |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 58 | size_t bos_dst = __bos0(dst); |
| 59 | if (__bos_trivially_not_lt(bos_dst, len)) { |
| 60 | return __builtin_memmove(dst, src, len); |
| 61 | } |
| 62 | return __builtin___memmove_chk(dst, src, len, bos_dst); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 63 | } |
| 64 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
| 65 | |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 66 | #if defined(__USE_GNU) |
| 67 | #if __ANDROID_API__ >= __ANDROID_API_R__ |
| 68 | __BIONIC_FORTIFY_INLINE |
| 69 | void* mempcpy(void* const dst __pass_object_size0, const void* src, size_t copy_amount) |
| 70 | __overloadable |
| 71 | __clang_error_if(__bos_unevaluated_lt(__bos0(dst), copy_amount), |
| 72 | "'mempcpy' called with size bigger than buffer") { |
| 73 | size_t bos_dst = __bos0(dst); |
| 74 | if (__bos_trivially_not_lt(bos_dst, copy_amount)) { |
| 75 | return __builtin_mempcpy(dst, src, copy_amount); |
| 76 | } |
| 77 | return __builtin___mempcpy_chk(dst, src, copy_amount, bos_dst); |
| 78 | } |
| 79 | #endif /* __ANDROID_API__ >= __ANDROID_API_R__ */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 80 | #endif /* __USE_GNU */ |
George Burgess IV | 849c0b9 | 2019-06-10 16:22:09 -0700 | [diff] [blame] | 81 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 82 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 83 | char* stpcpy(char* const dst __pass_object_size, const char* src) |
| 84 | __overloadable |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 85 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 86 | "'stpcpy' called with string bigger than buffer") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 87 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 88 | size_t bos_dst = __bos(dst); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 89 | if (!__bos_trivially_gt(bos_dst, __builtin_strlen(src))) { |
| 90 | return __builtin___stpcpy_chk(dst, src, bos_dst); |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 91 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 92 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 93 | return __builtin_stpcpy(dst, src); |
| 94 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 95 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 96 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 97 | char* strcpy(char* const dst __pass_object_size, const char* src) |
| 98 | __overloadable |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 99 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 100 | "'strcpy' called with string bigger than buffer") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 101 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 102 | size_t bos_dst = __bos(dst); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 103 | if (!__bos_trivially_gt(bos_dst, __builtin_strlen(src))) { |
| 104 | return __builtin___strcpy_chk(dst, src, bos_dst); |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 105 | } |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 106 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
| 107 | return __builtin_strcpy(dst, src); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 111 | char* strcat(char* const dst __pass_object_size, const char* src) |
| 112 | __overloadable |
| 113 | __clang_error_if(__bos_unevaluated_le(__bos(dst), __builtin_strlen(src)), |
| 114 | "'strcat' called with string bigger than buffer") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 115 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 116 | return __builtin___strcat_chk(dst, src, __bos(dst)); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 117 | #else |
| 118 | return __builtin_strcat(dst, src); |
| 119 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 120 | } |
| 121 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 122 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 123 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 124 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 125 | char* strncat(char* const dst __pass_object_size, const char* src, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 126 | return __builtin___strncat_chk(dst, src, n, __bos(dst)); |
| 127 | } |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 128 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 129 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 130 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 131 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 132 | void* memset(void* const s __pass_object_size0, int c, size_t n) __overloadable |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 133 | /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */ |
| 134 | __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 135 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 136 | size_t bos = __bos0(s); |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 137 | if (!__bos_trivially_ge(bos, n)) { |
| 138 | return __builtin___memset_chk(s, c, n, bos); |
George Burgess IV | 5da5dd5 | 2019-05-09 14:32:43 -0700 | [diff] [blame] | 139 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 140 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 141 | return __builtin_memset(s, c, n); |
| 142 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 143 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 144 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 145 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 146 | void* memchr(const void* const s __pass_object_size, int c, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 147 | size_t bos = __bos(s); |
| 148 | |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 149 | if (__bos_trivially_ge(bos, n)) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 150 | return __builtin_memchr(s, c, n); |
| 151 | } |
| 152 | |
| 153 | return __memchr_chk(s, c, n, bos); |
| 154 | } |
| 155 | |
| 156 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 157 | void* __memrchr_fortify(const void* const __pass_object_size s, int c, size_t n) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 158 | size_t bos = __bos(s); |
| 159 | |
George Burgess IV | c03d596 | 2019-05-23 15:22:01 -0700 | [diff] [blame] | 160 | if (__bos_trivially_ge(bos, n)) { |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 161 | return __memrchr_real(s, c, n); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | return __memrchr_chk(s, c, n, bos); |
| 165 | } |
| 166 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 167 | |
| 168 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 169 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 170 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 171 | char* stpncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 172 | __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 173 | size_t bos_dst = __bos(dst); |
| 174 | size_t bos_src = __bos(src); |
| 175 | |
| 176 | /* Ignore dst size checks; they're handled in strncpy_chk */ |
| 177 | if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 178 | return __builtin___stpncpy_chk(dst, src, n, bos_dst); |
| 179 | } |
| 180 | |
| 181 | return __stpncpy_chk2(dst, src, n, bos_dst, bos_src); |
| 182 | } |
| 183 | |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 184 | /* No diag -- clang diagnoses misuses of this on its own. */ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 185 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 186 | char* strncpy(char* const dst __pass_object_size, const char* const src __pass_object_size, size_t n) |
George Burgess IV | 36926f4 | 2019-09-15 16:57:00 -0700 | [diff] [blame] | 187 | __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 188 | size_t bos_dst = __bos(dst); |
| 189 | size_t bos_src = __bos(src); |
| 190 | |
| 191 | /* Ignore dst size checks; they're handled in strncpy_chk */ |
| 192 | if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 193 | return __builtin___strncpy_chk(dst, src, n, bos_dst); |
| 194 | } |
| 195 | |
| 196 | return __strncpy_chk2(dst, src, n, bos_dst, bos_src); |
| 197 | } |
| 198 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ |
| 199 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 200 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 201 | size_t strlcpy(char* const dst __pass_object_size, const char* src, size_t size) |
| 202 | __overloadable |
| 203 | __clang_error_if(__bos_unevaluated_lt(__bos(dst), size), |
| 204 | "'strlcpy' called with size bigger than buffer") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 205 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 206 | size_t bos = __bos(dst); |
| 207 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 208 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 209 | return __strlcpy_chk(dst, src, size, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 210 | } |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 211 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
| 212 | return __call_bypassing_fortify(strlcpy)(dst, src, size); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | 77f99aa | 2019-06-06 14:14:52 -0700 | [diff] [blame] | 216 | size_t strlcat(char* const dst __pass_object_size, const char* src, size_t size) |
| 217 | __overloadable |
| 218 | __clang_error_if(__bos_unevaluated_lt(__bos(dst), size), |
| 219 | "'strlcat' called with size bigger than buffer") { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 220 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 221 | size_t bos = __bos(dst); |
| 222 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 223 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 224 | return __strlcat_chk(dst, src, size, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 225 | } |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 226 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
| 227 | return __call_bypassing_fortify(strlcat)(dst, src, size); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 228 | } |
| 229 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 230 | __BIONIC_FORTIFY_INLINE |
George Burgess IV | b630046 | 2017-07-31 21:29:42 -0700 | [diff] [blame] | 231 | size_t strlen(const char* const s __pass_object_size0) __overloadable { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 232 | size_t bos = __bos0(s); |
| 233 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 234 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ |
| 235 | if (!__bos_trivially_gt(bos, __builtin_strlen(s))) { |
| 236 | return __strlen_chk(s, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 237 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 238 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 239 | return __builtin_strlen(s); |
| 240 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 241 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 242 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 243 | char* strchr(const char* const s __pass_object_size, int c) __overloadable { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 244 | #if __ANDROID_API__ >= __ANDROID_API_J_MR2__ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 245 | size_t bos = __bos(s); |
| 246 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 247 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 248 | return __strchr_chk(s, c, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 249 | } |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 250 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ |
| 251 | return __builtin_strchr(s, c); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 3f66e74 | 2017-08-01 13:24:40 -0700 | [diff] [blame] | 255 | char* strrchr(const char* const s __pass_object_size, int c) __overloadable { |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 256 | #if __ANDROID_API__ >= __ANDROID_API_J_MR2__ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 257 | size_t bos = __bos(s); |
| 258 | |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 259 | if (bos != __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 260 | return __strrchr_chk(s, c, bos); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 261 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 262 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ |
George Burgess IV | fd1ff4b | 2019-09-18 17:29:55 -0700 | [diff] [blame^] | 263 | return __builtin_strrchr(s, c); |
| 264 | } |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 265 | |
Elliott Hughes | df9a489 | 2017-08-23 14:34:03 -0700 | [diff] [blame] | 266 | #if __ANDROID_API__ >= __ANDROID_API_M__ |
| 267 | #if defined(__cplusplus) |
| 268 | extern "C++" { |
| 269 | __BIONIC_FORTIFY_INLINE |
| 270 | void* memrchr(void* const __pass_object_size s, int c, size_t n) { |
| 271 | return __memrchr_fortify(s, c, n); |
| 272 | } |
| 273 | |
| 274 | __BIONIC_FORTIFY_INLINE |
| 275 | const void* memrchr(const void* const __pass_object_size s, int c, size_t n) { |
| 276 | return __memrchr_fortify(s, c, n); |
| 277 | } |
| 278 | } |
| 279 | #else |
| 280 | __BIONIC_FORTIFY_INLINE |
| 281 | void* memrchr(const void* const __pass_object_size s, int c, size_t n) __overloadable { |
| 282 | return __memrchr_fortify(s, c, n); |
| 283 | } |
| 284 | #endif |
| 285 | #endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ |
| 286 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 287 | #endif /* defined(__BIONIC_FORTIFY) */ |