xref: /linux/tools/include/nolibc/unistd.h (revision 84b9b44b)
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 #define STDIN_FILENO  0
17 #define STDOUT_FILENO 1
18 #define STDERR_FILENO 2
19 
20 
21 static __attribute__((unused))
22 int msleep(unsigned int msecs)
23 {
24 	struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };
25 
26 	if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
27 		return (my_timeval.tv_sec * 1000) +
28 			(my_timeval.tv_usec / 1000) +
29 			!!(my_timeval.tv_usec % 1000);
30 	else
31 		return 0;
32 }
33 
34 static __attribute__((unused))
35 unsigned int sleep(unsigned int seconds)
36 {
37 	struct timeval my_timeval = { seconds, 0 };
38 
39 	if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
40 		return my_timeval.tv_sec + !!my_timeval.tv_usec;
41 	else
42 		return 0;
43 }
44 
45 static __attribute__((unused))
46 int usleep(unsigned int usecs)
47 {
48 	struct timeval my_timeval = { usecs / 1000000, usecs % 1000000 };
49 
50 	return sys_select(0, 0, 0, 0, &my_timeval);
51 }
52 
53 static __attribute__((unused))
54 int tcsetpgrp(int fd, pid_t pid)
55 {
56 	return ioctl(fd, TIOCSPGRP, &pid);
57 }
58 
59 /* make sure to include all global symbols */
60 #include "nolibc.h"
61 
62 #endif /* _NOLIBC_UNISTD_H */
63