diff mbox series

[uclibc-ng-devel] Add test to *stat() after 2038y with time64.

Message ID 20240226191328.623109-1-dm.chestnykh@gmail.com
State Accepted
Headers show
Series [uclibc-ng-devel] Add test to *stat() after 2038y with time64. | expand

Commit Message

Dmitry Chestnykh Feb. 26, 2024, 7:13 p.m. UTC
Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
---
 test/stat/stat-time64.c | 74 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 test/stat/stat-time64.c

Comments

Waldemar Brodkorb Feb. 27, 2024, 5:02 a.m. UTC | #1
Hi Dmitry,
Dmitry Chestnykh wrote,

> Signed-off-by: Dmitry Chestnykh <dm.chestnykh@gmail.com>
> ---
>  test/stat/stat-time64.c | 74 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
>  create mode 100644 test/stat/stat-time64.c

Thanks! Applied and pushed,
 best regards
  Waldemar
diff mbox series

Patch

diff --git a/test/stat/stat-time64.c b/test/stat/stat-time64.c
new file mode 100644
index 0000000..0102317
--- /dev/null
+++ b/test/stat/stat-time64.c
@@ -0,0 +1,74 @@ 
+/* Test for stat() after 2038 year.  */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <time.h>
+
+#define assert(x) \
+  if (!(x)) \
+    { \
+      fputs ("test failed: " #x "\n", stderr); \
+      retval = 1; \
+      goto the_end; \
+    }
+
+int
+main (int argc, char *argv[])
+{
+#if defined(__arm__) || defined(__mips__) || defined(__or1k__) || defined(__powerpc__) || defined(__sparc__) || defined(__xtensa__)
+  char name[PATH_MAX];
+  int retval = 0;
+  int fd;
+  struct stat st;
+
+  if (sizeof(time_t) == 8) {
+
+    memset(name, 0, PATH_MAX);
+
+    struct timespec y2090_ts = {
+      .tv_sec = 3786962400,
+      .tv_nsec = 0
+    };
+
+    assert(clock_settime (CLOCK_REALTIME, &y2090_ts) == 0);
+
+    /* hack to get a tempfile name w/out using tmpname()
+     * as that func causes a link time warning */
+    sprintf(name, "%s-uClibc-test.XXXXXX", __FILE__);
+    fd = mkstemp(name);
+
+    assert(stat (name, &st) == 0)
+    assert(st.st_atime >= 3786962400);
+    assert(st.st_mtime >= 3786962400);
+    assert(st.st_ctime >= 3786962400);
+
+    assert(fstat (fd, &st) == 0)
+    assert(st.st_atime >= 3786962400);
+    assert(st.st_mtime >= 3786962400);
+    assert(st.st_ctime >= 3786962400);
+
+    assert(lstat (name, &st) == 0)
+    assert(st.st_atime >= 3786962400);
+    assert(st.st_mtime >= 3786962400);
+    assert(st.st_ctime >= 3786962400);
+
+    close(fd);
+    retval = 0;
+
+the_end:
+    unlink (name);
+
+    return retval;
+  }
+  else {
+    printf("Nothing to test.\n");
+  }
+#else
+  printf("Nothing to test.\n");
+  return 0;
+#endif
+}