select.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_SYS_SELECT_H
  16. #define _FORTIFY_SYS_SELECT_H
  17. __extension__
  18. #include_next <sys/select.h>
  19. #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
  24. void __fortify_FD_CLR(int __f, fd_set *__s)
  25. {
  26. size_t __b = __builtin_object_size(__s, 0);
  27. if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
  28. __builtin_trap();
  29. FD_CLR(__f, __s);
  30. }
  31. static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
  32. void __fortify_FD_SET(int __f, fd_set *__s)
  33. {
  34. size_t __b = __builtin_object_size(__s, 0);
  35. if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
  36. __builtin_trap();
  37. FD_SET(__f, __s);
  38. }
  39. #undef FD_CLR
  40. #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set)
  41. #undef FD_SET
  42. #define FD_SET(fd, set) __fortify_FD_SET(fd, set)
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif
  47. #endif