Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/strtotimex.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 653 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 }