blob: 91d827aa222d95e6f44556fff335165cb26af9f8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <time.h>
11
12#define MAX_POSITIVE(type) (~0 & ~((type) 1 << (sizeof(type)*8 - 1)))
13
14int do_test(int argc, char **argv) {
15 char *correct = 0, *s;
16 int status;
17
18 /* need a very high positive number (e.g., max - 1024) */
19 time_t test = MAX_POSITIVE(time_t) - 1024;
20
21 s = asctime(localtime(&test));
22
23 if (s) {
24 // copy static buffer to heap
25 correct = malloc(strlen(s)+1);
26 strcpy(correct, s);
27 }
28
29 s = ctime(&test);
30
31 printf("ANSI:\t%suClibc:\t%s", correct, s);
32
33 if (s != correct && strcmp(correct, s))
34 status = EXIT_FAILURE;
35 else
36 status = EXIT_SUCCESS;
37
38 if (correct)
39 free(correct);
40
41 return status;
42}
43
44#include <test-skeleton.c>