pread和pwrite未定义? [英] pread and pwrite not defined?
问题描述
我正在尝试使用pread和pwrite,以便可以查找文件的开头并开始在一个原子操作中进行读取或写入.这两个函数都会为我做到这一点,但是,我遇到的问题是,即使我添加了 #define _XOPEN_SOURCE 500,编译器也向我发出警告:函数"pread"的隐式声明
和#include< unistd.h>
就像手册页中所说的那样.我想念什么吗?下面是带有函数调用的两个语句.谢谢!
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)
{
推荐答案
您需要在包含以下内容之前定义 _XOPEN_SOURCE 500
:>
You need to define _XOPEN_SOURCE 500
before your includes:
#define _XOPEN_SOURCE 500
#include<unistd.h>
否则, unistd.h
标头将看不到宏定义.
Otherwise, the unistd.h
header won't see the macro definition.
这篇关于pread和pwrite未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!