Mercurial > hg > octave-nkf > gnulib-hg
comparison lib/nanosleep.c @ 2052:3c79d37078c2
*** empty log message ***
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sat, 25 Dec 1999 22:15:23 +0000 |
parents | |
children | 0d23f740f281 |
comparison
equal
deleted
inserted
replaced
2051:20197e046796 | 2052:3c79d37078c2 |
---|---|
1 /* Provide a replacement for the POSIX nanosleep function. | |
2 Copyright (C) 1999 Free Software Foundation, Inc. | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program 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 | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | |
18 /* written by Jim Meyering */ | |
19 | |
20 #include <config.h> | |
21 | |
22 #include <sys/types.h> | |
23 | |
24 #include <time.h> | |
25 /* FIXME: is including both like this kosher? */ | |
26 #include <sys/time.h> | |
27 | |
28 static interrupted; | |
29 | |
30 /* Sleep for USEC microseconds. */ | |
31 | |
32 static void | |
33 usleep (const struct timespec *ts_delay) | |
34 { | |
35 struct timeval tv_delay; | |
36 tv_delay.tv_sec = ts_delay->tv_sec; | |
37 tv_delay.tv_usec = 1000 * ts_delay->tv_nsec; | |
38 select (0, (void *) 0, (void *) 0, (void *) 0, tv_delay); | |
39 } | |
40 | |
41 int | |
42 nanosleep (const struct timespec *requested_delay, | |
43 struct timespec *remaining_delay) | |
44 { | |
45 interrupted = 0; | |
46 | |
47 /* set up sig handler -- but maybe only do this the first time? */ | |
48 /* FIXME */ | |
49 | |
50 usleep (requested_delay); | |
51 | |
52 if (interrupted) | |
53 { | |
54 /* Calculate time remaining. */ | |
55 /* FIXME: the code in sleep doesn't use this, so there's no | |
56 rush to implement it. */ | |
57 } | |
58 | |
59 /* FIXME: Restore sig handler? */ | |
60 | |
61 return interrupted; | |
62 } |