Updated to fedora-glibc-20060425T0903
[glibc/history.git] / posix / tst-nanosleep.c
blob0fa0135bc6a56de92e85f4c3afc702094fb28db5
1 /* Copyright (C) 2003 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 <errno.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <sys/time.h>
23 #include <time.h>
26 /* Test that nanosleep() does sleep. */
27 static int
28 do_test (void)
30 /* Current time. */
31 struct timeval tv1;
32 (void) gettimeofday (&tv1, NULL);
34 struct timespec ts;
35 ts.tv_sec = 1;
36 ts.tv_nsec = 0;
37 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
39 /* At least one second must have passed. */
40 struct timeval tv2;
41 (void) gettimeofday (&tv2, NULL);
43 tv2.tv_sec -= tv1.tv_sec;
44 tv2.tv_usec -= tv1.tv_usec;
45 if (tv2.tv_usec < 0)
46 --tv2.tv_sec;
48 if (tv2.tv_sec < 1)
50 puts ("nanosleep didn't sleep long enough");
51 return 1;
54 return 0;
57 #define TEST_FUNCTION do_test ()
58 #include "../test-skeleton.c"