summaryrefslogtreecommitdiffstats
path: root/usr/klibc/strtotimex.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:06:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:06:04 +0000
commit2f0649f6fe411d7e07c8d56cf8ea56db53536da8 (patch)
tree778611fb52176dce1ad06c68e87b2cb348ca0f7b /usr/klibc/strtotimex.c
parentInitial commit. (diff)
downloadklibc-5d59bef0406ec5b526d04080317d1f3898723a76.tar.xz
klibc-5d59bef0406ec5b526d04080317d1f3898723a76.zip
Adding upstream version 2.0.13.upstream/2.0.13upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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;
+}