integers.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * integers.h:
  3. * This header file ensures that we have u_int<n>_t types of the proper width,
  4. * using a rather convoluted set of conditionals generated by configure. This
  5. * is an almighty pain in the arse, and is completely irrelevant on most
  6. * systems which already define this stuff.
  7. *
  8. * $Id: integers.h,v 1.1 2002/11/04 12:28:43 chris Exp $
  9. *
  10. */
  11. #ifndef __INTEGERS_H_ /* include guard */
  12. #define __INTEGERS_H_
  13. #include <sys/types.h>
  14. #include "config.h"
  15. #if SIZEOF_U_INT8_T != 1 || SIZEOF_U_INT16_T != 2 || SIZEOF_U_INT32_T != 4
  16. # if defined(HAVE_C99_INTS)
  17. /*
  18. * Use the C99 standard-width integers, defined in some appropriate
  19. * header file.
  20. */
  21. # if defined(HAVE_STDINT_H)
  22. # include <stdint.h>
  23. # elif defined(HAVE_SYS_INTTYPES_H)
  24. # include <sys/inttypes.h>
  25. # endif
  26. /* Don't replace existing u_int<n>_t types. */
  27. # if SIZEOF_U_INT8_T != 1
  28. typedef uint8_t u_int8_t;
  29. # endif
  30. # if SIZEOF_U_INT16_T != 2
  31. typedef uint16_t u_int16_t;
  32. # endif
  33. # if SIZEOF_U_INT32_T != 4
  34. typedef uint32_t u_int32_t;
  35. # endif
  36. # elif (SIZEOF_UNSIGNED_SHORT_INT == 2 || SIZEOF_UNSIGNED_INT == 2) \
  37. && (SIZEOF_UNSIGNED_INT == 4 || SIZEOF_UNSIGNED_LONG_INT == 4)
  38. /*
  39. * Use an appropriately-sized basic type.
  40. */
  41. # if SIZEOF_U_INT8_T != 1
  42. typedef unsigned char u_int8_t; /* By definition. */
  43. # endif
  44. # if SIZEOF_U_INT16_T != 2
  45. # if SIZEOF_UNSIGNED_SHORT_INT == 2
  46. typedef unsigned short int u_int16_t;
  47. # elif SIZEOF_UNSIGNED_INT == 2
  48. typedef unsigned int u_int16_t; /* Not likely. */
  49. # endif
  50. # endif
  51. # if SIZEOF_U_INT32_T != 4
  52. # if SIZEOF_UNSIGNED_INT == 4
  53. typedef unsigned int u_int32_t;
  54. # elif SIZEOF_UNSIGNED_LONG_INT == 4
  55. typedef unsigned long int u_int32_t;
  56. # endif
  57. # endif
  58. /* Whew. */
  59. # else
  60. # error "Your C compiler seems to lack 16 and 32 bit unsigned integer types"
  61. # endif
  62. #endif /* No existing u_int<n>_t types. */
  63. #endif /* __INTEGERS_H_ */