我有一个 C 应用程序,它偶尔无法打开存储在/tmp
共享上的文件。
这是相关的代码块:
// open file and start parsing
notStdin = strcmp(inFile, "-");
if (notStdin) {
coordsIn = fopen(inFile, "r"); <----- inFile = file that I want to open
if (coordsIn == NULL) {
fprintf(stderr, "ERROR: Could not open coordinates file: %s\n\t%s\n", inFile, strerror(errno));
exit(EXIT_FAILURE);
}
}
else
coordsIn = stdin;
Run Code Online (Sandbox Code Playgroud)
在八到十次试验中,我得到一个NULL
FILE 指针。这是一个示例错误消息:
ERROR: Could not open coordinates file: /tmp/coordinates.txt
File or directory does not exist
Run Code Online (Sandbox Code Playgroud)
但是,该文件/tmp/coordinates.txt
确实存在,因为我可以使用head
、cat
或more
等标准实用程序打开它。 …