* MODULES.html.sh (Support for systems lacking POSIX:2001): New
[gnulib.git] / tests / test-gettimeofday.c
1 /*
2  * Copyright (C) 2005, 2007 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 #include <config.h>
21
22 #include <sys/time.h>
23
24 #include <stdio.h>
25 #include <string.h>
26
27 suseconds_t dummy = 0;  /* just to test if this type is available */
28
29 int
30 main (int argc, char *argv[])
31 {
32   time_t t = 0;
33   struct tm *lt;
34   struct tm saved_lt;
35   struct timeval tv;
36   lt = localtime (&t);
37   saved_lt = *lt;
38   gettimeofday (&tv, NULL);
39   if (memcmp (lt, &saved_lt, sizeof (struct tm)) != 0)
40     {
41       fprintf (stderr, "gettimeofday still clobbers the localtime buffer!\n");
42       return 1;
43     }
44   else
45     {
46       return 0;
47     }
48 }