* sysdeps/mach/hurd/bits/fcntl.h [__USE_GNU__] (F_DUPFD_CLOEXEC): New.
[glibc.git] / time / test_time.c
blob20216ed9d24faceefb47e5f347a1c34df423e147
1 /* Copyright (C) 1991, 1992, 1994, 1997 Free Software Foundation, Inc.
2 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.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <time.h>
24 int
25 main (int argc, char **argv)
27 time_t t;
28 register struct tm *tp;
29 struct tm tbuf;
30 int lose = 0;
32 --argc;
33 ++argv;
37 char buf[BUFSIZ];
38 if (argc > 0)
40 static char buf[BUFSIZ];
41 sprintf(buf, "TZ=%s", *argv);
42 if (putenv(buf))
44 puts("putenv failed.");
45 lose = 1;
47 else
48 puts (buf);
50 tzset();
51 tbuf.tm_year = 72;
52 tbuf.tm_mon = 0;
53 tbuf.tm_mday = 31;
54 tbuf.tm_hour = 6;
55 tbuf.tm_min = 14;
56 tbuf.tm_sec = 50;
57 tbuf.tm_isdst = -1;
58 doit:;
59 t = mktime(&tbuf);
60 if (t == (time_t) -1)
62 puts("mktime() failed?");
63 lose = 1;
65 tp = localtime(&t);
66 if (tp == NULL)
68 puts("localtime() failed.");
69 lose = 1;
71 else if (strftime(buf, sizeof(buf), "%a %b %d %X %Z %Y", tp) == 0)
73 puts("strftime() failed.");
74 lose = 1;
76 else
77 puts(buf);
78 if (tbuf.tm_year == 101)
80 tbuf.tm_year = 97;
81 tbuf.tm_mon = 0;
82 goto doit;
84 ++argv;
85 } while (--argc > 0);
88 #define SIZE 256
89 char buffer[SIZE];
90 time_t curtime;
91 struct tm *loctime;
93 curtime = time (NULL);
95 loctime = localtime (&curtime);
97 fputs (asctime (loctime), stdout);
99 strftime (buffer, SIZE, "Today is %A, %B %d.\n", loctime);
100 fputs (buffer, stdout);
101 strftime (buffer, SIZE, "The time is %I:%M %p.\n", loctime);
102 fputs (buffer, stdout);
104 loctime->tm_year = 72;
105 loctime->tm_mon = 8;
106 loctime->tm_mday = 12;
107 loctime->tm_hour = 20;
108 loctime->tm_min = 49;
109 loctime->tm_sec = 05;
110 curtime = mktime (loctime);
111 strftime (buffer, SIZE, "%D %T was %w the %jth.\n", loctime);
112 fputs (buffer, stdout);
115 return (lose ? EXIT_FAILURE : EXIT_SUCCESS);