]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/test/time/tst-ctime.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / test / time / tst-ctime.c
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
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
14 int 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>