Annotation of /trunk/mkinitrd-magellan/klibc/usr/klibc/strtotimex.c
Parent Directory | Revision Log
Revision 815 -
(hide annotations)
(download)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 671 byte(s)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 671 byte(s)
-updated to klibc-1.5.15
1 | niro | 532 | /* |
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 | niro | 815 | #include <time.h> |
14 | niro | 532 | #include <sys/time.h> |
15 | |||
16 | char *NAME(const char *str, TIMEX * ts) | ||
17 | { | ||
18 | int n; | ||
19 | char *s, *s0; | ||
20 | __typeof__(ts->FSEC) fs; /* Fractional seconds */ | ||
21 | |||
22 | ts->tv_sec = strntoumax(str, &s, 10, ~(size_t) 0); | ||
23 | fs = 0; | ||
24 | |||
25 | if (*s == '.') { | ||
26 | s0 = s + 1; | ||
27 | |||
28 | fs = strntoumax(s0, &s, 10, DECIMALS); | ||
29 | n = s - s0; | ||
30 | |||
31 | while (isdigit(*s)) | ||
32 | s++; | ||
33 | |||
34 | for (; n < DECIMALS; n++) | ||
35 | fs *= 10; | ||
36 | } | ||
37 | |||
38 | ts->FSEC = fs; | ||
39 | return s; | ||
40 | } |