strings.h (1815B)
1 /* 2 * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> 3 * Copyright (C) 2022 q66 <q66@chimera-linux.org> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef _FORTIFY_STRINGS_H 18 #define _FORTIFY_STRINGS_H 19 20 #include_next <strings.h> 21 22 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 23 #include "fortify-headers.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ 30 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ 31 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 32 #undef bcopy 33 #undef bzero 34 __access(write_only, 2, 3) 35 __access(read_only, 1, 3) 36 _FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, 37 void * _FORTIFY_POS0 __d, size_t __n) 38 { 39 size_t __bd = __bos(__d, 0); 40 size_t __bs = __bos(__s, 0); 41 42 if (__n > __bd || __n > __bs) 43 __builtin_trap(); 44 return __orig_bcopy(__s, __d, __n); 45 } 46 47 __access(write_only, 1, 2) 48 _FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) 49 { 50 size_t __b = __bos(__s, 0); 51 52 if (__n > __b) 53 __builtin_trap(); 54 return __orig_bzero(__s, __n); 55 } 56 #endif 57 58 #ifdef __cplusplus 59 } 60 #endif 61 62 #endif 63 64 #endif