From e60cf78e7ed50bb9d24da63b0a8f406bb4bf4ff9 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Thu, 8 Oct 2020 18:37:56 +0300 Subject: [PATCH] syscall_to_function.h: simplify, and avoid C++20 extension The macros in syscall_to_function.h used "__VA_OPT__", which is a C++20 extension that older compilers (such as on Ubuntu 18.04) don't understand. Luckily, we don't even need to use this extension. The macros in this file used an elaborate way to change __OSV_TO_FUNCTION_SYS_fcntl to just "fcntl" with all the parameters intact. But the easiest way to achieve that goal is just to #define the name - without even telling the C preprocessor that this is a function! It will just change "__OSV_TO_FUNCTION_SYS_fcntl" to "fcntl" and not worry at all about anything which may or may not appear afterwards in parentheses. It's easier, shorter, and not C++20-specific. Fixes #1099 Signed-off-by: Nadav Har'El --- libc/syscall_to_function.h | 42 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/libc/syscall_to_function.h b/libc/syscall_to_function.h index 87cd27df7e..0f1172cae3 100644 --- a/libc/syscall_to_function.h +++ b/libc/syscall_to_function.h @@ -2,33 +2,21 @@ #include #include -#define sys_open(filename, flags, ...) (open(filename, flags __VA_OPT__(,) __VA_ARGS__)) - -#define __OSV_TO_FUNCTION_SYS_open(filename, flags, ...) (open(filename, flags __VA_OPT__(,) __VA_ARGS__)) - -#define __OSV_TO_FUNCTION_SYS_close(fd) (close(fd)) - -#define __OSV_TO_FUNCTION_SYS_lseek(file, off, whence) (lseek(file, off, whence)) - -#define __OSV_TO_FUNCTION_SYS_fcntl(fd, cmd, ...) (fcntl(fd, cmd __VA_OPT__(,) __VA_ARGS__)) - -#define __OSV_TO_FUNCTION_SYS_clock_gettime(c, t, x) (clock_gettime(c, t)) - -#define __OSV_TO_FUNCTION_SYS_access(p, i) (access(p, i)) - -#define __OSV_TO_FUNCTION_SYS_ioctl(fd, cmd, args) (ioctl(fd, cmd, args)) - -#define __OSV_TO_FUNCTION_SYS_fstat(fd, st) (fstat(fd, st)) - -#define __OSV_TO_FUNCTION_SYS_lstat(fd, st) (lstat(fd, st)) - -#define __OSV_TO_FUNCTION_SYS_unlink(path) (unlink(path)) - -#define __OSV_TO_FUNCTION_SYS_rmdir(path) (rmdir(path)) - -#define __OSV_TO_FUNCTION_SYS_readv(fd, cmd, args) (readv(fd, cmd, args)) - -#define __OSV_TO_FUNCTION_SYS_writev(fd, cmd, args) (writev(fd, cmd, args)) +#define sys_open open + +#define __OSV_TO_FUNCTION_SYS_open open +#define __OSV_TO_FUNCTION_SYS_close close +#define __OSV_TO_FUNCTION_SYS_lseek lseek +#define __OSV_TO_FUNCTION_SYS_fcntl fcntl +#define __OSV_TO_FUNCTION_SYS_clock_gettime clock_gettime +#define __OSV_TO_FUNCTION_SYS_access access +#define __OSV_TO_FUNCTION_SYS_ioctl ioctl +#define __OSV_TO_FUNCTION_SYS_fstat fstat +#define __OSV_TO_FUNCTION_SYS_lstat lstat +#define __OSV_TO_FUNCTION_SYS_unlink unlink +#define __OSV_TO_FUNCTION_SYS_rmdir rmdir +#define __OSV_TO_FUNCTION_SYS_readv readv +#define __OSV_TO_FUNCTION_SYS_writev writev #undef __syscall #define __syscall(sys_number, ...) (__OSV_TO_FUNCTION_##sys_number(__VA_ARGS__) < 0 ? -errno : 0)