I write a code to generate system call
void open_test(int fd, const char *filepath) {
if (fd == -1) {
printf(&qu
You call via the syscall(2)
wrapper: syscall(SYS_open, ...)
:
#define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <sys/syscall.h>
int main(void){
char *path = "whatever.txt";
int fd = syscall(SYS_open, path, O_RDONLY, 0);
if(fd == -1) err(1, "SYS_open %s", path);
}
But why bother? SYS_openat
is the canonical system call now, open(2)
is just an API, and the SYS_open
system call entry is only kept for backward binary compatibility.
On newer architectures, there may be no actual SYS_open
system call at all.