summaryrefslogtreecommitdiffstats
path: root/usr/klibc/strtotimex.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/strtotimex.c')
-rw-r--r--usr/klibc/strtotimex.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/usr/klibc/strtotimex.c b/usr/klibc/strtotimex.c
new file mode 100644
index 0000000..0624082
--- /dev/null
+++ b/usr/klibc/strtotimex.c
@@ -0,0 +1,40 @@
+/*
+ * strtotimex.c
+ *
+ * Nonstandard function which takes a string and converts it to a
+ * struct timespec/timeval. Returns a pointer to the first non-numeric
+ * character in the string.
+ *
+ */
+
+#include <ctype.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+
+char *NAME(const char *str, TIMEX * ts)
+{
+ int n;
+ char *s, *s0;
+ __typeof__(ts->FSEC) fs; /* Fractional seconds */
+
+ ts->tv_sec = strntoumax(str, &s, 10, ~(size_t) 0);
+ fs = 0;
+
+ if (*s == '.') {
+ s0 = s + 1;
+
+ fs = strntoumax(s0, &s, 10, DECIMALS);
+ n = s - s0;
+
+ while (isdigit(*s))
+ s++;
+
+ for (; n < DECIMALS; n++)
+ fs *= 10;
+ }
+
+ ts->FSEC = fs;
+ return s;
+}