_store_inttype.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include "_stdio.h"
  8. #include <printf.h>
  9. /* Right now, we assume intmax_t is either long or long long */
  10. #ifdef INTMAX_MAX
  11. #ifdef LLONG_MAX
  12. #if INTMAX_MAX > LLONG_MAX
  13. #error INTMAX_MAX > LLONG_MAX! The printf code needs to be updated!
  14. #endif
  15. #elif INTMAX_MAX > LONG_MAX
  16. #error No LLONG_MAX and INTMAX_MAX > LONG_MAX! The printf code needs to be updated!
  17. #endif /* LLONG_MAX */
  18. #endif /* INTMAX_MAX */
  19. /* We assume int may be short or long, but short and long are different. */
  20. void _store_inttype(register void *dest, int desttype, uintmax_t val) attribute_hidden;
  21. void _store_inttype(register void *dest, int desttype, uintmax_t val)
  22. {
  23. if (desttype == __PA_FLAG_CHAR) { /* assume char not int */
  24. *((unsigned char *) dest) = val;
  25. return;
  26. }
  27. #if defined(LLONG_MAX) && (INT_MAX != LLONG_MAX)
  28. if (desttype == PA_FLAG_LONG_LONG) {
  29. *((unsigned long long int *) dest) = val;
  30. return;
  31. }
  32. #endif /* LLONG_MAX */
  33. #if SHRT_MAX != INT_MAX
  34. if (desttype == PA_FLAG_SHORT) {
  35. *((unsigned short int *) dest) = val;
  36. return;
  37. }
  38. #endif /* SHRT_MAX */
  39. #if LONG_MAX != INT_MAX
  40. if (desttype == PA_FLAG_LONG) {
  41. *((unsigned long int *) dest) = val;
  42. return;
  43. }
  44. #endif /* LONG_MAX */
  45. *((unsigned int *) dest) = val;
  46. }