calendarspec: sub-second support, v3
This commit is contained in:
@@ -490,3 +490,39 @@ int safe_atod(const char *s, double *ret_d) {
|
||||
*ret_d = (double) d;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
|
||||
size_t i;
|
||||
unsigned val = 0;
|
||||
const char *s;
|
||||
|
||||
s = *p;
|
||||
|
||||
/* accept any number of digits, strtoull is limted to 19 */
|
||||
for(i=0; i < digits; i++,s++) {
|
||||
if (*s < '0' || *s > '9') {
|
||||
if (i == 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* too few digits, pad with 0 */
|
||||
for (; i < digits; i++)
|
||||
val *= 10;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
val *= 10;
|
||||
val += *s - '0';
|
||||
}
|
||||
|
||||
/* maybe round up */
|
||||
if (*s >= '5' && *s <= '9')
|
||||
val++;
|
||||
|
||||
s += strspn(s, DIGITS);
|
||||
|
||||
*p = s;
|
||||
*res = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user