commit ceba9e9fa10db6fce6b270de7a803a9734337002
parent 0203cf6fd97f26960bb1c6e747d8d72f76033479
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 22 Apr 2026 12:10:45 +0200
tests/libc: Add 0070-difftime
Diffstat:
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -68,3 +68,4 @@ test.log
0067-wcwidth
0068-fseek
0069-mktime
+0070-difftime
diff --git a/tests/libc/execute/0070-difftime.c b/tests/libc/execute/0070-difftime.c
@@ -0,0 +1,34 @@
+/*
+output:
+testing
+done
+end:
+*/
+
+#include <assert.h>
+#include <stdio.h>
+#include <time.h>
+
+int
+test(void)
+{
+ double d1, d2;
+ time_t t1, t2;
+
+ for (t1 = t2 = time(NULL); difftime(t1, t2) < 0.005; t2 = time(NULL))
+ ;
+
+ d1 = difftime(t1, t2);
+ d2 = difftime(t2, t1);
+ assert(d1 + d2 < 0.0005);
+}
+
+int
+main(void)
+{
+ puts("testing");
+ test();
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -66,3 +66,4 @@
0067-wcwidth [TODO]
0068-fseek
0069-mktime
+0070-difftime