private.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* $OpenBSD: private.h,v 1.25 2012/09/13 11:14:20 millert Exp $ */
  2. #ifndef PRIVATE_H
  3. #define PRIVATE_H
  4. /*
  5. ** This file is in the public domain, so clarified as of
  6. ** 1996-06-05 by Arthur David Olson.
  7. */
  8. /*
  9. ** Nested includes
  10. */
  11. #include "sys/types.h" /* for time_t */
  12. #include "stdio.h"
  13. #include "errno.h"
  14. #include "string.h"
  15. #include "limits.h" /* for CHAR_BIT et al. */
  16. #include "time.h"
  17. /*
  18. ** Finally, some convenience items.
  19. */
  20. #ifndef TRUE
  21. #define TRUE 1
  22. #endif /* !defined TRUE */
  23. #ifndef FALSE
  24. #define FALSE 0
  25. #endif /* !defined FALSE */
  26. #ifndef TYPE_BIT
  27. #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
  28. #endif /* !defined TYPE_BIT */
  29. #ifndef TYPE_SIGNED
  30. #define TYPE_SIGNED(type) (((type) -1) < 0)
  31. #endif /* !defined TYPE_SIGNED */
  32. /*
  33. ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
  34. ** it cannot be used in preprocessor directives.
  35. */
  36. #ifndef TYPE_INTEGRAL
  37. #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
  38. #endif /* !defined TYPE_INTEGRAL */
  39. #ifndef INT_STRLEN_MAXIMUM
  40. /*
  41. ** 302 / 1000 is log10(2.0) rounded up.
  42. ** Subtract one for the sign bit if the type is signed;
  43. ** add one for integer division truncation;
  44. ** add one more for a minus sign if the type is signed.
  45. */
  46. #define INT_STRLEN_MAXIMUM(type) \
  47. ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
  48. 1 + TYPE_SIGNED(type))
  49. #endif /* !defined INT_STRLEN_MAXIMUM */
  50. /* Disable warnings */
  51. #endif /* !defined PRIVATE_H */