Update contrib.
2 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 * * Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
22 #include <sys/timespec.h>
23 #include <sys/select.h>
26 //#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
29 int nanosleep(const struct timespec *req, struct timespec *rem)
33 struct timeval tstart, tstop, tremain, time2wait;
39 TIMESPEC_TO_TIMEVAL(&time2wait, req);
40 (void) gettimeofday(&tstart, NULL);
41 rc = select(0, NULL, NULL, NULL, &time2wait);
44 (void) gettimeofday (&tstop, NULL);
46 tremain.tv_sec = time2wait.tv_sec -
47 (tstop.tv_sec - tstart.tv_sec);
48 tremain.tv_usec = time2wait.tv_usec -
49 (tstop.tv_usec - tstart.tv_usec);
50 tremain.tv_sec += tremain.tv_usec / 1000000L;
51 tremain.tv_usec %= 1000000L;
58 TIMEVAL_TO_TIMESPEC(&tremain, rem);