2
0

string_number.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*============================================================================
  2. string_number
  3. ==============================================================================
  4. This file contains utilities for dealing with text string representation
  5. of numbers.
  6. ============================================================================*/
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <errno.h>
  10. #include <xmlrpc-c/base.h>
  11. #include <xmlrpc-c/util.h>
  12. #include <xmlrpc-c/string_int.h>
  13. #include "xmlrpc_config.h"
  14. #include "int.h"
  15. #include <xmlrpc-c/string_number.h>
  16. void
  17. xmlrpc_parse_int64(xmlrpc_env * const envP,
  18. const char * const str,
  19. xmlrpc_int64 * const i64P) {
  20. xmlrpc_int64 i64val;
  21. char * tail;
  22. errno = 0;
  23. i64val = XMLRPC_STRTOLL(str, &tail, 10);
  24. if (errno == ERANGE)
  25. xmlrpc_faultf(envP, "Number cannot be represented in 64 bits. "
  26. "Must be in the range "
  27. "[%" XMLRPC_PRId64 " - %" XMLRPC_PRId64 "]",
  28. XMLRPC_INT64_MIN, XMLRPC_INT64_MAX);
  29. else if (errno != 0)
  30. xmlrpc_faultf(envP, "unexpected error: "
  31. "strtoll() failed with errno %d (%s)",
  32. errno, strerror(errno));
  33. else if (tail[0] != '\0')
  34. xmlrpc_faultf(envP, "contains non-numerical junk: '%s'", tail);
  35. else
  36. *i64P = i64val;
  37. }