examples/terminals: better fcntl wrapper
#endif
#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/syscall.h>
@@ -16,11 +18,21 @@ int close(int fd)
return syscall(__NR_close, fd);
}
-int fcntl(int fd, int cmd, uintptr_t a1, uintptr_t a2)
+int fcntl(int __fd, int __cmd, ...)
{
- if (fd == 1022 || fd == 1023) {
- errno = EBADF;
- return -1;
+ va_list ap;
+ va_start(ap, __cmd);
+ int a1 = va_arg(ap, int);
+ int a2 = va_arg(ap, int);
+ int a3 = va_arg(ap, int);
+ int a4 = va_arg(ap, int);
+ va_end(ap);
+
+ if (__fd == 1022 || __fd == 1023) {
+ if (__cmd == F_SETFD) {
+ a1 &= ~(FD_CLOEXEC);
}
- return syscall(__NR_fcntl, fd, cmd, a1, a2);
+ }
+
+ return syscall(__NR_fcntl, __fd, __cmd, a1, a2, a3, a4);
}
