getrandom syscall in C not found

前端 未结 5 1565
温柔的废话
温柔的废话 2020-12-17 16:27

The problem was resolved by upgrading the C library.


I would like to use the syscall getrandom (http://man7.org/linux/man-pages/man2/getrandom.2.html)

5条回答
  •  没有蜡笔的小新
    2020-12-17 17:21

    So, it seems that getrandom is not a function, just a syscall.

    Hence this is needed:

    /* Note that this define is required for syscalls to work. */
    #define _GNU_SOURCE
    
    #include 
    #include 
    #include 
    
    int main(int arg, char *argv[])
    {
            void *buf = NULL;
            size_t l = 5;
            unsigned int o = 1;
            int r = syscall(SYS_getrandom, buf, l, o);
            return 0;
    }
    

提交回复
热议问题