chiark / gitweb /
[PATCH] update klibc to version 0.181
[elogind.git] / klibc / klibc / strtotimex.c
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 <sys/time.h>
14
15 char * NAME (const char *str, TIMEX *ts)
16 {
17   int n;
18   char *s, *s0;
19   __typeof__(ts->FSEC) fs;      /* Fractional seconds */
20
21   ts->tv_sec = strntoumax(str, &s, 10, ~(size_t)0);
22   fs = 0;
23
24   if ( *s == '.' ) {
25     s0 = s+1;
26
27     fs = strntoumax(s0, &s, 10, DECIMALS);
28     n = s-s0;
29     
30     while ( isdigit(*s) )
31       s++;
32     
33     for ( ; n < DECIMALS ; n++ )
34       fs *= 10;
35   }
36
37   ts->FSEC = fs;
38   return s;
39 }