minmax.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @file minmax.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. * @section DESCRIPTION
  23. *
  24. * Minimum and maximum macros.
  25. */
  26. #ifndef BADVPN_MISC_MINMAX_H
  27. #define BADVPN_MISC_MINMAX_H
  28. #include <stddef.h>
  29. #include <stdint.h>
  30. #define DEFINE_BMINMAX(name, type) \
  31. static type bmin ## name (type a, type b) { return (a < b ? a : b); } \
  32. static type bmax ## name (type a, type b) { return (a > b ? a : b); }
  33. DEFINE_BMINMAX(_size, size_t)
  34. DEFINE_BMINMAX(_int, int)
  35. DEFINE_BMINMAX(_int8, int8_t)
  36. DEFINE_BMINMAX(_int16, int16_t)
  37. DEFINE_BMINMAX(_int32, int32_t)
  38. DEFINE_BMINMAX(_int64, int64_t)
  39. DEFINE_BMINMAX(_uint, unsigned int)
  40. DEFINE_BMINMAX(_uint8, uint8_t)
  41. DEFINE_BMINMAX(_uint16, uint16_t)
  42. DEFINE_BMINMAX(_uint32, uint32_t)
  43. DEFINE_BMINMAX(_uint64, uint64_t)
  44. #endif