/d == per day (24 hours)
*/
ParameterError err = PARAM_OK;
- const char *div = strchr(nextarg, '/');
- char number[26];
- long denominator;
- long numerator = 60 * 60 * 1000; /* default per hour */
- size_t numlen = div ? (size_t)(div - nextarg) : strlen(nextarg);
- if(numlen > sizeof(number) - 1)
- return PARAM_NUMBER_TOO_LARGE;
-
- memcpy(number, nextarg, numlen);
- number[numlen] = 0;
- err = str2unum(&denominator, number);
- if(err)
- return err;
+ const char *p = nextarg;
+ curl_off_t denominator;
+ curl_off_t numerator = 60 * 60 * 1000; /* default per hour */
+
+ if(curlx_str_number(&p, &denominator, CURL_OFF_T_MAX))
+ return PARAM_BAD_NUMERIC;
if(denominator < 1)
return PARAM_BAD_USE;
- if(div) {
+ if(!curlx_str_single(&p, '/')) {
curl_off_t numunits;
- div++;
- if(curlx_str_number(&div, &numunits, CURL_OFF_T_MAX))
+ if(curlx_str_number(&p, &numunits, CURL_OFF_T_MAX))
numunits = 1;
- switch(*div) {
+ switch(*p) {
case 's': /* per second */
numerator = 1000;
break;
break;
}
- if((LONG_MAX / numerator) < numunits) {
+ if((CURL_OFF_T_MAX / numerator) < numunits) {
/* overflow, too large number */
errorf("too large --rate unit");
err = PARAM_NUMBER_TOO_LARGE;
}
else
/* this typecast is okay based on the check above */
- numerator *= (long)numunits;
+ numerator *= numunits;
}
if(err)