stat-time64.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Test for stat() after 2038 year. */
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8. #include <time.h>
  9. #define assert(x) \
  10. if (!(x)) \
  11. { \
  12. fputs ("test failed: " #x "\n", stderr); \
  13. retval = 1; \
  14. goto the_end; \
  15. }
  16. int
  17. main (int argc, char *argv[])
  18. {
  19. #if defined(__arm__) || defined(__mips__) || defined(__or1k__) || defined(__powerpc__) || defined(__sparc__) || defined(__xtensa__)
  20. char name[PATH_MAX];
  21. int retval = 0;
  22. int fd;
  23. struct stat st;
  24. if (sizeof(time_t) == 8) {
  25. memset(name, 0, PATH_MAX);
  26. struct timespec y2090_ts = {
  27. .tv_sec = 3786962400,
  28. .tv_nsec = 0
  29. };
  30. assert(clock_settime (CLOCK_REALTIME, &y2090_ts) == 0);
  31. /* hack to get a tempfile name w/out using tmpname()
  32. * as that func causes a link time warning */
  33. sprintf(name, "%s-uClibc-test.XXXXXX", __FILE__);
  34. fd = mkstemp(name);
  35. assert(stat (name, &st) == 0)
  36. assert(st.st_atime >= 3786962400);
  37. assert(st.st_mtime >= 3786962400);
  38. assert(st.st_ctime >= 3786962400);
  39. assert(fstat (fd, &st) == 0)
  40. assert(st.st_atime >= 3786962400);
  41. assert(st.st_mtime >= 3786962400);
  42. assert(st.st_ctime >= 3786962400);
  43. assert(lstat (name, &st) == 0)
  44. assert(st.st_atime >= 3786962400);
  45. assert(st.st_mtime >= 3786962400);
  46. assert(st.st_ctime >= 3786962400);
  47. close(fd);
  48. retval = 0;
  49. the_end:
  50. unlink (name);
  51. return retval;
  52. }
  53. else {
  54. printf("Nothing to test.\n");
  55. }
  56. #else
  57. printf("Nothing to test.\n");
  58. return 0;
  59. #endif
  60. }