diff options
| -rw-r--r-- | include/strings.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/strings.h b/include/strings.h new file mode 100644 index 0000000..db08cc9 --- /dev/null +++ b/include/strings.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #ifndef FORTIFY_STRINGS_H_ | ||
| 2 | #define FORTIFY_STRINGS_H_ | ||
| 3 | |||
| 4 | #include_next <strings.h> | ||
| 5 | |||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 7 | |||
| 8 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 9 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 10 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 11 | |||
| 12 | static inline __attribute__ ((always_inline)) | ||
| 13 | void __fortify_bcopy(const void *__restrict src, void *__restrict dest, size_t n) | ||
| 14 | { | ||
| 15 | size_t bos = __builtin_object_size(dest, 0); | ||
| 16 | |||
| 17 | if (n > bos) | ||
| 18 | __builtin_trap(); | ||
| 19 | return bcopy(src, dest, n); | ||
| 20 | } | ||
| 21 | |||
| 22 | #undef bcopy | ||
| 23 | #define bcopy(src, dest, n) __fortify_bcopy(src, dest, n) | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif | ||
| 27 | |||
| 28 | #endif | ||
