sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Permission to use, copy, modify, and distribute this software for any
|
sl@0
|
5 |
* purpose with or without fee is hereby granted, provided that the above
|
sl@0
|
6 |
* copyright notice and this permission notice appear in all copies.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
sl@0
|
9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
sl@0
|
10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
sl@0
|
11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
sl@0
|
12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
sl@0
|
13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
sl@0
|
14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
sl@0
|
15 |
* * Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <sys/time.h>
|
sl@0
|
22 |
#include <sys/timespec.h>
|
sl@0
|
23 |
#include <sys/select.h>
|
sl@0
|
24 |
#include <errno.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
//#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
|
sl@0
|
27 |
|
sl@0
|
28 |
EXPORT_C
|
sl@0
|
29 |
int nanosleep(const struct timespec *req, struct timespec *rem)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
int rc, saverrno;
|
sl@0
|
32 |
extern int errno;
|
sl@0
|
33 |
struct timeval tstart, tstop, tremain, time2wait;
|
sl@0
|
34 |
|
sl@0
|
35 |
if(!req)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
return 0 ;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
TIMESPEC_TO_TIMEVAL(&time2wait, req);
|
sl@0
|
40 |
(void) gettimeofday(&tstart, NULL);
|
sl@0
|
41 |
rc = select(0, NULL, NULL, NULL, &time2wait);
|
sl@0
|
42 |
if (rc == -1) {
|
sl@0
|
43 |
saverrno = errno;
|
sl@0
|
44 |
(void) gettimeofday (&tstop, NULL);
|
sl@0
|
45 |
errno = saverrno;
|
sl@0
|
46 |
tremain.tv_sec = time2wait.tv_sec -
|
sl@0
|
47 |
(tstop.tv_sec - tstart.tv_sec);
|
sl@0
|
48 |
tremain.tv_usec = time2wait.tv_usec -
|
sl@0
|
49 |
(tstop.tv_usec - tstart.tv_usec);
|
sl@0
|
50 |
tremain.tv_sec += tremain.tv_usec / 1000000L;
|
sl@0
|
51 |
tremain.tv_usec %= 1000000L;
|
sl@0
|
52 |
} else {
|
sl@0
|
53 |
tremain.tv_sec = 0;
|
sl@0
|
54 |
tremain.tv_usec = 0;
|
sl@0
|
55 |
}
|
sl@0
|
56 |
if(rem)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TIMEVAL_TO_TIMESPEC(&tremain, rem);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
return(rc);
|
sl@0
|
62 |
}
|
sl@0
|
63 |
//#endif
|