[英]fstat() return 0, with file size 0 and errno 11
I'm trying the following thing in my code:- 我正在代码中尝试以下操作:
{
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);
}
and the output that I'm getting is :- 我得到的输出是:
Success - 0, size -> 0 , Error - 11
After write Success - 0, size -> 0, Error - 11 and the value of n_bytes is - 1526
What is the reason behind the size being 0 and the error number 11?? 大小为0且错误号为11的原因是什么? Is there any other way to get the size of the file??
还有其他方法可以获取文件大小吗?
Note: here Netdev->queue_fd[class_id]
is a file descriptor. 注意:这里
Netdev->queue_fd[class_id]
是文件描述符。 The value of n_bytes is varying in between {41,1514,66,..} in different calls. 在不同的调用中,n_bytes的值在{41,1514,66,..}之间变化。 (Always greater than 0)
(始终大于0)
thanks 谢谢
The status of errno
after success is irrelevant. 成功后
errno
的状态无关紧要。 The value of errno
is only modified upon failure. errno
的值仅在失败时修改。 fstat()
returned zero, so the value of errno is doesn't matter. fstat()
返回零,因此errno的值无关紧要。
What does write()
return? write()
返回什么? You're not checking so you don't know that the file should be larger after the write()
call. 您没有检查,因此您不知道在
write()
调用之后文件应该更大。
Netdev->queue_fd[class_id]
is a file descriptor of Netdev->queue_fd[class_id]
是以下文件的文件描述符
if it is not a regular file then its size will not be updated after write command . 如果它不是常规文件,则在执行写命令后不会更新其大小 。
check file tyeps by S_ISREG()
通过
S_ISREG()
检查文件类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.