sl@0: /* sl@0: * Copyright (c) 1999-2004 Damien Miller sl@0: * sl@0: * Permission to use, copy, modify, and distribute this software for any sl@0: * purpose with or without fee is hereby granted, provided that the above sl@0: * copyright notice and this permission notice appear in all copies. sl@0: * sl@0: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES sl@0: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF sl@0: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR sl@0: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES sl@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN sl@0: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF sl@0: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. sl@0: * * Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: */ sl@0: sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: //#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) sl@0: sl@0: EXPORT_C sl@0: int nanosleep(const struct timespec *req, struct timespec *rem) sl@0: { sl@0: int rc, saverrno; sl@0: extern int errno; sl@0: struct timeval tstart, tstop, tremain, time2wait; sl@0: sl@0: if(!req) sl@0: { sl@0: return 0 ; sl@0: } sl@0: TIMESPEC_TO_TIMEVAL(&time2wait, req); sl@0: (void) gettimeofday(&tstart, NULL); sl@0: rc = select(0, NULL, NULL, NULL, &time2wait); sl@0: if (rc == -1) { sl@0: saverrno = errno; sl@0: (void) gettimeofday (&tstop, NULL); sl@0: errno = saverrno; sl@0: tremain.tv_sec = time2wait.tv_sec - sl@0: (tstop.tv_sec - tstart.tv_sec); sl@0: tremain.tv_usec = time2wait.tv_usec - sl@0: (tstop.tv_usec - tstart.tv_usec); sl@0: tremain.tv_sec += tremain.tv_usec / 1000000L; sl@0: tremain.tv_usec %= 1000000L; sl@0: } else { sl@0: tremain.tv_sec = 0; sl@0: tremain.tv_usec = 0; sl@0: } sl@0: if(rem) sl@0: { sl@0: TIMEVAL_TO_TIMESPEC(&tremain, rem); sl@0: } sl@0: sl@0: return(rc); sl@0: } sl@0: //#endif