pread and pwrite not defined?

﹥>﹥吖頭↗ 提交于 2021-02-16 20:20:50

问题


I am trying to use pread and pwrite so that I can lseek to the beginning of the file and start reading or writing in one atomic operation. Both of these functions will do that for me however, the issue I am having is that the compiler is giving me warning: implicit declaration of function ‘pread’ even after I added #define _XOPEN_SOURCE 500 and #include<unistd.h> like the man pages said. Am I missing something? The two statements with the function calls are below. Thanks!

 #include<unistd.h>



 #define _XOPEN_SOURCE 500
    int main (int argc, char *argv[])
    {



while ( (read_in += pread(source_fd, in_buf, in_buf_size,read_in) )  )
    {

if (write_out += pwrite(dest_fd, in_buf, read_in, write_out) == -1)
        {

回答1:


You need to define _XOPEN_SOURCE 500 before your includes:

#define _XOPEN_SOURCE 500

#include<unistd.h>

Otherwise, the unistd.h header won't see the macro definition.



来源:https://stackoverflow.com/questions/12411942/pread-and-pwrite-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!