how to call sys_open rather than sys_openat when calling open

后端 未结 1 1344
遇见更好的自我
遇见更好的自我 2021-01-23 04:15

I write a code to generate system call

void open_test(int fd, const char *filepath) {
    if (fd == -1) {
        printf(&qu         


        
相关标签:
1条回答
  • 2021-01-23 04:32

    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.

    0 讨论(0)
提交回复
热议问题