tst-strftime4.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Test strftime and strptime after 2038-01-19 03:14:07 UTC (bug 30053).
  2. Copyright (C) 2023-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <time.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <support/check.h>
  20. static int
  21. do_test (void)
  22. {
  23. TEST_VERIFY_EXIT (setenv ("TZ", "UTC0", 1) == 0);
  24. tzset ();
  25. if (sizeof (time_t) > 4)
  26. {
  27. time_t wrap = (time_t) 2147483648LL;
  28. char buf[80];
  29. struct tm *tm = gmtime (&wrap);
  30. TEST_VERIFY_EXIT (tm != NULL);
  31. TEST_VERIFY_EXIT (strftime (buf, sizeof buf, "%s", tm) > 0);
  32. puts (buf);
  33. TEST_VERIFY (strcmp (buf, "2147483648") == 0);
  34. struct tm tm2;
  35. char *p = strptime (buf, "%s", &tm2);
  36. TEST_VERIFY_EXIT (p != NULL && *p == '\0');
  37. time_t t = mktime (&tm2);
  38. printf ("%lld\n", (long long) t);
  39. TEST_VERIFY (t == wrap);
  40. }
  41. else
  42. FAIL_UNSUPPORTED ("32-bit time_t");
  43. return 0;
  44. }
  45. #include <support/test-driver.c>