【发布时间】:2015-02-09 14:38:55
【问题描述】:
该文件存在,我刚刚在另一个函数中读取它。另一个函数关闭文件。现在,我的workwith() 尝试打开它并从中读取。
我的代码:
if (access(path_file, F_OK) != -1) {
// file exists
*mfs_desc = open(path_file, O_WRONLY | O_RDONLY, 0600);
if (*mfs_desc == -1) {
perror("opening file");
exit(1);
}
printf("file_descriptor = %d, filename = |%s|\n", *mfs_desc,
path_file);
if ((read(*mfs_desc, superblock, sizeof(Superblock))) == - 1) {
perror("read superblock");
exit(1);
}
}
但是,我得到了这个输出:
file_descriptor = 3, filename = |t.mfs|
read superblock: Bad file descriptor
我怀疑我打开文件的方式不正确。我想打开文件以进行读写。该文件已经存在。我错过了什么?
【问题讨论】: