读取系统调用未检测到文件结尾 [英] Read system call not detecting End of file
本文介绍了读取系统调用未检测到文件结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过串口将调制解调器连接到我的电脑(linux),我正在尝试使用写入和读取系统调用从调制解调器写入和读取.在从调制解调器读取所有数据后读取读取系统调用块期间,在我的我已经检查了 eof 的代码,如下所示
I have connected a modem to my pc(linux) through serial port and i am trying to write to and read from modem using write and read system call.During reading read system call blocks after reading all data from modem,in my code i have made check for eof as shown below
while(1)
{
if((rd_cnt =read(fd, &str, 1)) <=0)
{
perror("Read to dev failed");
printf("error no=%d\n",errno);
break;
}
printf("char =%c -> hex=%x rd_cnt=%d\n",str,str,rd_cnt);
sleep(3);
str=0;
}
if(rd_cnt==0)
printf("EOF met\n");
但我从来没有收到过 eof,我想读取从调制解调器发送的所有数据,直到遇到文件结尾.请指导我.
but i have never got eof,i wanted to read all the data send from modem till i meet end of file. Please guide me.
推荐答案
像这样改变你的代码
if((rd_cnt =read(fd, &str, sizeof(str))) <=0)
{
perror("Read to dev failed");
printf("error no=%d\n",errno);
break;
}
检查EOF
条件即可.
无需再次编写此代码,因为您已经在检查它.
No need to write this code again as you are already checking this.
//if(rd_cnt==0)
//printf("EOF met\n");
这篇关于读取系统调用未检测到文件结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文