Skip to content

Commit

Permalink
syscall_to_function.h: simplify, and avoid C++20 extension
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nyh committed Oct 8, 2020
1 parent bd3c1e8 commit e60cf78
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions libc/syscall_to_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,21 @@
#include <unistd.h>
#include <errno.h>

#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)
Expand Down

0 comments on commit e60cf78

Please sign in to comment.