tst-ctime.c 920 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* vi: set sw=4 ts=4: */
  2. /* testcase for ctime(3) with large time
  3. * Copyright (C) 2010 David A Ramos <daramos@gustav.stanford.edu>
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #define MAX_POSITIVE(type) (~0 & ~((type) 1 << (sizeof(type)*8 - 1)))
  11. int do_test(int argc, char **argv) {
  12. char *correct = 0, *s;
  13. int status;
  14. /* need a very high positive number (e.g., max - 1024) */
  15. time_t test = MAX_POSITIVE(time_t) - 1024;
  16. s = asctime(localtime(&test));
  17. if (s) {
  18. // copy static buffer to heap
  19. correct = malloc(strlen(s)+1);
  20. strcpy(correct, s);
  21. }
  22. s = ctime(&test);
  23. printf("ANSI:\t%suClibc:\t%s", correct, s);
  24. if (s != correct && strcmp(correct, s))
  25. status = EXIT_FAILURE;
  26. else
  27. status = EXIT_SUCCESS;
  28. if (correct)
  29. free(correct);
  30. return status;
  31. }
  32. #include <test-skeleton.c>