1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
3 * unistd function definitions for NOLIBC
4 * Copyright (C) 2017-2022 Willy Tarreau <w@1wt.eu>
7 #ifndef _NOLIBC_UNISTD_H
8 #define _NOLIBC_UNISTD_H
16 #define STDIN_FILENO 0
17 #define STDOUT_FILENO 1
18 #define STDERR_FILENO 2
21 static __attribute__((unused
))
22 int msleep(unsigned int msecs
)
24 struct timeval my_timeval
= { msecs
/ 1000, (msecs
% 1000) * 1000 };
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);
34 static __attribute__((unused
))
35 unsigned int sleep(unsigned int seconds
)
37 struct timeval my_timeval
= { seconds
, 0 };
39 if (sys_select(0, 0, 0, 0, &my_timeval
) < 0)
40 return my_timeval
.tv_sec
+ !!my_timeval
.tv_usec
;
45 static __attribute__((unused
))
46 int usleep(unsigned int usecs
)
48 struct timeval my_timeval
= { usecs
/ 1000000, usecs
% 1000000 };
50 return sys_select(0, 0, 0, 0, &my_timeval
);
53 static __attribute__((unused
))
54 int tcsetpgrp(int fd
, pid_t pid
)
56 return ioctl(fd
, TIOCSPGRP
, &pid
);
59 #define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
60 #define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
61 #define _syscall(N, ...) __sysret(my_syscall##N(__VA_ARGS__))
62 #define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
63 #define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
65 /* make sure to include all global symbols */
68 #endif /* _NOLIBC_UNISTD_H */