MCPcopy Create free account
hub / github.com/F-Stack/f-stack / string2ull

Function string2ull

app/redis-6.2.6/src/util.c:456–469  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

454 * 1 if the conversion happened successfully or 0 if the number is
455 * invalid or out of range. */
456int 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

Callers 2

Calls 1

string2llFunction · 0.70

Tested by

no test coverage detected