Helper function to convert a string to an unsigned long long value. * The function attempts to use the faster string2ll() function inside * Redis: if it fails, strtoull() is used instead. The function returns * 1 if the conversion happened successfully or 0 if the number is * invalid or out of range. */
| 454 | * 1 if the conversion happened successfully or 0 if the number is |
| 455 | * invalid or out of range. */ |
| 456 | int string2ull(const char *s, unsigned long long *value) { |
| 457 | long long ll; |
| 458 | if (string2ll(s,strlen(s),&ll)) { |
| 459 | if (ll < 0) return 0; /* Negative values are out of range. */ |
| 460 | *value = ll; |
| 461 | return 1; |
| 462 | } |
| 463 | errno = 0; |
| 464 | char *endptr = NULL; |
| 465 | *value = strtoull(s,&endptr,10); |
| 466 | if (errno == EINVAL || errno == ERANGE || !(*s != '\0' && *endptr == '\0')) |
| 467 | return 0; /* strtoull() failed. */ |
| 468 | return 1; /* Conversion done! */ |
| 469 | } |
| 470 | |
| 471 | /* Convert a string into a long. Returns 1 if the string could be parsed into a |
| 472 | * (non-overflowing) long, 0 otherwise. The value will be set to the parsed |
no test coverage detected