man fread manual:
RETURN VALUE
fread() and fwrite() return the number of items successfully read or
written (i.e., not the number of characters). If an error occurs, or
the end-of-file is reached, the return value is a short item count (or
zero).
fread() does not distinguish between end-of-file and error, and callers
must use feof(3) and ferror(3) to determine which occurred.
The function feof() tests the end-of-file indicator for the stream pointed to by stream, returning nonzero if it is set. The end-of-file indicator can only be cleared by the function clearerr().
The function ferror() tests the error indicator for the stream pointed to by stream, returning nonzero if it is set. The error indicator can only be reset by the clearerr() function.
feof()和ferror()无法主动检测快到文件末尾或读取出现错误;只有fread返回0或小于读取字节数的时候,用这个两个函数来区分;
while(1)
{
bzero(stAVData, sizeof(StYaanIpcFrameHead));
s32SendLen = fread(&stAVData, sizeof(char), sizeof(StYaanIpcFrameHead), pFd);
if(feof(pFd) || ferror(pFd)) //来检查是否出错;
{
printf("Fread frame header failed!\n");
break;
}
}