os/ossrv/genericopenlibs/openenvcore/libc/src/nanosleep.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/nanosleep.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,63 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
     1.6 + *
     1.7 + * Permission to use, copy, modify, and distribute this software for any
     1.8 + * purpose with or without fee is hereby granted, provided that the above
     1.9 + * copyright notice and this permission notice appear in all copies.
    1.10 + *
    1.11 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    1.12 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    1.13 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    1.14 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    1.15 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    1.16 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    1.17 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    1.18 + * * Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.19 + */
    1.20 +
    1.21 +
    1.22 +
    1.23 +
    1.24 +#include <sys/time.h>
    1.25 +#include <sys/timespec.h>
    1.26 +#include <sys/select.h>
    1.27 +#include <errno.h>
    1.28 +
    1.29 +//#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
    1.30 +
    1.31 +EXPORT_C 
    1.32 +int nanosleep(const struct timespec *req, struct timespec *rem)
    1.33 +{
    1.34 +        int rc, saverrno;
    1.35 +        extern int errno;
    1.36 +        struct timeval tstart, tstop, tremain, time2wait;
    1.37 +
    1.38 +        if(!req)
    1.39 +        	{ 
    1.40 +        		return 0 ;
    1.41 +        	} 	 
    1.42 +        TIMESPEC_TO_TIMEVAL(&time2wait, req);
    1.43 +        (void) gettimeofday(&tstart, NULL);
    1.44 +        rc = select(0, NULL, NULL, NULL, &time2wait);
    1.45 +        if (rc == -1) {
    1.46 +                saverrno = errno;
    1.47 +                (void) gettimeofday (&tstop, NULL);
    1.48 +                errno = saverrno;
    1.49 +                tremain.tv_sec = time2wait.tv_sec -
    1.50 +                        (tstop.tv_sec - tstart.tv_sec);
    1.51 +                tremain.tv_usec = time2wait.tv_usec -
    1.52 +                        (tstop.tv_usec - tstart.tv_usec);
    1.53 +                tremain.tv_sec += tremain.tv_usec / 1000000L;
    1.54 +                tremain.tv_usec %= 1000000L;
    1.55 +        } else {
    1.56 +                tremain.tv_sec = 0;
    1.57 +                tremain.tv_usec = 0;
    1.58 +        }
    1.59 +        if(rem)
    1.60 +        	{
    1.61 +        	TIMEVAL_TO_TIMESPEC(&tremain, rem);
    1.62 +        	}
    1.63 +
    1.64 +        return(rc);
    1.65 +}
    1.66 +//#endif