【发布时间】:2021-10-25 21:47:48
【问题描述】:
我正在尝试将一些数据写入文件。 fwrite 正在返回 EAGAIN 并且 fwrite_explain 说:
2: fwrite(ptr = 0x7F41EFBC09A8, size = 4066, nmemb = 1, fp = 0x02F79200 "/home/user/asdf.txt") failed, Resource temporarily unavailable (11, EAGAIN) because the file descriptor has been marked non-blocking (O_NONBLOCK) and the write would block
2: fwrite(ptr = 0x17ECFFA40, size = 4066, nmemb = 1, fp = 0x02F79200 "/home/user/asdf.txt") failed, No such file or directory (2, ENOENT) because the file is on a file system ("/home", 1% full) which does not support Unix open file semantics, and the file has been deleted from underneath you
2: fwrite(ptr = 0x17ECFF100, size = 4066, nmemb = 1, fp = 0x02F79200 "/home/user/asdf.txt") failed, No such file or directory (2, ENOENT) because the file is on a file system ("/home", 1% full) which does not support Unix open file semantics, and the file has been deleted from underneath you
我假设第二组警告无效(文件永远不会被删除,它仍然存在)。
我从不将我的文件设置为非阻塞,我不在乎它是否阻塞,因为我想写入数据,不管它可能需要多长时间。什么给了?
相关代码:
fd = fopen(file_to_write, "w");
if (fd == NULL) printf("%d could not open file\n", errno);
n = fwrite((void*)h->bufs[i], write_size, 1, fd);
if (n != write_size) {
printf("%d: %s\n", errno, explain_fwrite((void*)h->bufs[i], write_size, 1, fd));
【问题讨论】: