_store_inttype.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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)
  21. {
  22. if (desttype == __PA_FLAG_CHAR) { /* assume char not int */
  23. *((unsigned char *) dest) = val;
  24. return;
  25. }
  26. #if defined(LLONG_MAX) && (INT_MAX != LLONG_MAX)
  27. if (desttype == PA_FLAG_LONG_LONG) {
  28. *((unsigned long long int *) dest) = val;
  29. return;
  30. }
  31. #endif /* LLONG_MAX */
  32. #if SHRT_MAX != INT_MAX
  33. if (desttype == PA_FLAG_SHORT) {
  34. *((unsigned short int *) dest) = val;
  35. return;
  36. }
  37. #endif /* SHRT_MAX */
  38. #if LONG_MAX != INT_MAX
  39. if (desttype == PA_FLAG_LONG) {
  40. *((unsigned long int *) dest) = val;
  41. return;
  42. }
  43. #endif /* LONG_MAX */
  44. *((unsigned int *) dest) = val;
  45. }