1 #if !defined(_GNU_SOURCE) 2 #define _GNU_SOURCE 3 #endif 4 5 #include <errno.h> 6 #include <fcntl.h> 7 #include <stdarg.h> 8 #include <stdint.h> 9 #include <stdio.h> 10 #include <sys/syscall.h> 11 #include <unistd.h> 12 13 int close(int fd) 14 { 15 if (fd == 1022 || fd == 1023) { 16 return 0; 17 } 18 return syscall(__NR_close, fd); 19 } 20 21 int fcntl(int __fd, int __cmd, ...) 22 { 23 va_list ap; 24 va_start(ap, __cmd); 25 int a1 = va_arg(ap, int); 26 int a2 = va_arg(ap, int); 27 int a3 = va_arg(ap, int); 28 int a4 = va_arg(ap, int); 29 va_end(ap); 30 31 if (__fd == 1022 || __fd == 1023) { 32 if (__cmd == F_SETFD) { 33 a1 &= ~(FD_CLOEXEC); 34 } 35 } 36 37 return syscall(__NR_fcntl, __fd, __cmd, a1, a2, a3, a4); 38 } 39