Root/
Source at commit 1078 created 13 years 1 month ago. By azimutz, Put back message removed by mistake on r1061. | |
---|---|
1 | /*␊ |
2 | * strtotimex.c␊ |
3 | *␊ |
4 | * Nonstandard function which takes a string and converts it to a␊ |
5 | * struct timespec/timeval. Returns a pointer to the first non-numeric␊ |
6 | * character in the string.␊ |
7 | *␊ |
8 | */␊ |
9 | ␊ |
10 | #include <ctype.h>␊ |
11 | #include <inttypes.h>␊ |
12 | #include <stdlib.h>␊ |
13 | #include <time.h>␊ |
14 | #include <sys/time.h>␊ |
15 | ␊ |
16 | uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n);␊ |
17 | ␊ |
18 | char *NAME(const char *str, TIMEX * ts)␊ |
19 | {␊ |
20 | ␉int n;␊ |
21 | ␉char *s, *s0;␊ |
22 | ␉__typeof__(ts->FSEC) fs;␉/* Fractional seconds */␊ |
23 | ␊ |
24 | ␉ts->tv_sec = strntoumax(str, &s, 10, ~(size_t) 0);␊ |
25 | ␉fs = 0;␊ |
26 | ␊ |
27 | ␉if (*s == '.') {␊ |
28 | ␉␉s0 = s + 1;␊ |
29 | ␊ |
30 | ␉␉fs = strntoumax(s0, &s, 10, DECIMALS);␊ |
31 | ␉␉n = s - s0;␊ |
32 | ␊ |
33 | ␉␉while (isdigit(*s))␊ |
34 | ␉␉␉s++;␊ |
35 | ␊ |
36 | ␉␉for (; n < DECIMALS; n++)␊ |
37 | ␉␉␉fs *= 10;␊ |
38 | ␉}␊ |
39 | ␊ |
40 | ␉ts->FSEC = fs;␊ |
41 | ␉return s;␊ |
42 | }␊ |
43 |