1 /**
2  * \file   dietlibc/lib/backends/simple_sleep/sleep.c
3  * \brief
4  *
5  * \date   08/10/2004
6  * \author Martin Pohlack  <mp26@os.inf.tu-dresden.de>
7  */
8 /*
9  * (c) 2004-2009 Author(s)
10  *     economic rights: Technische Universität Dresden (Germany)
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU Lesser General Public License 2.1.
13  * Please see the COPYING-LGPL-2.1 file for details.
14  */
15 #include <errno.h>
16 #include <sys/time.h>
17 #include <time.h>
18 
19 #include <l4/util/util.h>
20 
nanosleep(const struct timespec * req,struct timespec * rem)21 int nanosleep(const struct timespec *req, struct timespec *rem)
22 {
23     int milis;
24 
25     (void)rem;
26     if (req == NULL)
27     {
28         errno = EFAULT; // or maybe EINVAL ???
29         return -1;
30     }
31 
32     if (req->tv_nsec < 0 || req->tv_nsec > 999999999 || req->tv_sec < 0)
33     {
34         errno = EINVAL;
35         return -1;
36     }
37 
38     milis = (req->tv_sec * 1000) + (req->tv_nsec / 1000000);
39     l4_sleep(milis);
40 
41     return 0;
42 }
43