Patch from Martin Lambers <marlam@marlam.de>, from 2005-10-08
[pspp] / tests / test-gettimeofday.c
1 /*
2  * Copyright (C) 2005 Free Software Foundation
3  * Written by Jim Meyering.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.  */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <string.h>
26
27 #if TIME_WITH_SYS_TIME
28 # include <sys/time.h>
29 # include <time.h>
30 #else
31 # if HAVE_SYS_TIME_H
32 #  include <sys/time.h>
33 # else
34 #  include <time.h>
35 # endif
36 #endif
37
38 #include "gettimeofday.h"
39
40 int
41 main (int argc, char *argv[])
42 {
43   suseconds_t dummy = 0;        /* just to test if this type is available */
44   time_t t = 0;
45   struct tm *lt;
46   struct tm saved_lt;
47   struct timeval tv;
48   lt = localtime (&t);
49   saved_lt = *lt;
50   gettimeofday (&tv, NULL);
51   if (memcmp (lt, &saved_lt, sizeof (struct tm)) != 0)
52     {
53       fprintf (stderr, "gettimeofday still clobbers the localtime buffer!\n");
54       return 1;
55     }
56   else
57     {
58       return 0;
59     }
60 }