用lseek+read函数读入文件不存在的位置,然后没有报错,程序并没有崩溃.为什么?
如下所示的程序:(/tmp/test1文件已经有内容了)
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
using namespace std;
int main()
{
int fd=open("/tmp/test1",O_RDONLY);
lseek(fd,2,SEEK_END);
cout << errno << endl;
char buf[4]={0};
int r=read(fd,buf,3);
cout << "r=" << r << ",errno=" << errno << "buf=" << buf << endl;
return 0;
}