我正在我的代码中尝试以下操作:-
{
int y,n_bytes;
struct stat temp_data;
y = fstat(netdev->queue_fd[class_id],&temp_data);
printf("Success - %d , size -> %lld , Error- %d \n",y,temp_data.st_size,errno);
n_bytes = write(netdev->queue_fd[class_id],buffer->data,buffer->size);
y = fstat(netdev->queue_fd[class_id],&temp_data);
printf("After write Success - %d , size -> %lld , Error- %d and the value of n_bytes is - %d ",y,temp_data.st_size,errno,n_bytes);
}
我得到的输出是:-
Success - 0, size -> 0 , Error - 11
After write Success - 0, size -> 0, Error - 11 and the value of n_bytes is - 1526
大小为 0 且错误编号为 11 的原因是什么?? 还有其他方法可以获取文件的大小吗??
注意:这里的Netdev->queue_fd[class_id]
是一个文件描述符。
n_bytes 的值在不同的调用中在 {41,1514,66,..} 之间变化。 (总是大于 0)
谢谢
最佳答案
成功后
errno
的状态无关紧要。errno
的值仅在失败时修改。fstat()
返回零,因此 errno 的值无关紧要。write()
返回什么?您没有检查,所以您不知道在write()
调用之后文件应该更大。
关于c - fstat() 返回 0,文件大小为 0,错误号为 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29940981/