blimits.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @file blimits.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_BLIMITS_H
  23. #define BADVPN_BLIMITS_H
  24. #include <stdint.h>
  25. #define BTYPE_IS_SIGNED(type) ((type)-1 < 0)
  26. #define BSIGNED_TYPE_MIN(type) ( \
  27. sizeof(type) == 1 ? INT8_MIN : ( \
  28. sizeof(type) == 2 ? INT16_MIN : ( \
  29. sizeof(type) == 4 ? INT32_MIN : ( \
  30. sizeof(type) == 8 ? INT64_MIN : 0))))
  31. #define BSIGNED_TYPE_MAX(type) ( \
  32. sizeof(type) == 1 ? INT8_MAX : ( \
  33. sizeof(type) == 2 ? INT16_MAX : ( \
  34. sizeof(type) == 4 ? INT32_MAX : ( \
  35. sizeof(type) == 8 ? INT64_MAX : 0))))
  36. #define BUNSIGNED_TYPE_MIN(type) ((type)0)
  37. #define BUNSIGNED_TYPE_MAX(type) ( \
  38. sizeof(type) == 1 ? UINT8_MAX : ( \
  39. sizeof(type) == 2 ? UINT16_MAX : ( \
  40. sizeof(type) == 4 ? UINT32_MAX : ( \
  41. sizeof(type) == 8 ? UINT64_MAX : 0))))
  42. #define BTYPE_MIN(type) (BTYPE_IS_SIGNED(type) ? BSIGNED_TYPE_MIN(type) : BUNSIGNED_TYPE_MIN(type))
  43. #define BTYPE_MAX(type) (BTYPE_IS_SIGNED(type) ? BSIGNED_TYPE_MAX(type) : BUNSIGNED_TYPE_MAX(type))
  44. #endif