xref: /linux/tools/include/nolibc/unistd.h (revision 0e9b70c1e3623fa110fb6be553e644524228ef60)
1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2 /*
3  * unistd function definitions for NOLIBC
4  * Copyright (C) 2017-2022 Willy Tarreau <w@1wt.eu>
5  */
6 
7 #ifndef _NOLIBC_UNISTD_H
8 #define _NOLIBC_UNISTD_H
9 
10 #include "std.h"
11 #include "arch.h"
12 #include "types.h"
13 #include "sys.h"
14 
15 
16 static __attribute__((unused))
17 int msleep(unsigned int msecs)
18 {
19 	struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };
20 
21 	if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
22 		return (my_timeval.tv_sec * 1000) +
23 			(my_timeval.tv_usec / 1000) +
24 			!!(my_timeval.tv_usec % 1000);
25 	else
26 		return 0;
27 }
28 
29 static __attribute__((unused))
30 unsigned int sleep(unsigned int seconds)
31 {
32 	struct timeval my_timeval = { seconds, 0 };
33 
34 	if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
35 		return my_timeval.tv_sec + !!my_timeval.tv_usec;
36 	else
37 		return 0;
38 }
39 
40 static __attribute__((unused))
41 int usleep(unsigned int usecs)
42 {
43 	struct timeval my_timeval = { usecs / 1000000, usecs % 1000000 };
44 
45 	return sys_select(0, 0, 0, 0, &my_timeval);
46 }
47 
48 static __attribute__((unused))
49 int tcsetpgrp(int fd, pid_t pid)
50 {
51 	return ioctl(fd, TIOCSPGRP, &pid);
52 }
53 
54 /* make sure to include all global symbols */
55 #include "nolibc.h"
56 
57 #endif /* _NOLIBC_UNISTD_H */
58