strings.h 1.6 KB

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