【发布时间】:2018-03-21 18:37:46
【问题描述】:
我正在 Raspbian 上编译一个 Angband 变体,但以下失败:
struct stat txt_stat, raw_stat;
/* Build the filename */
path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
/* Access stats on text file */
if (stat(buf, &txt_stat))
{
/* Error */
msg_format("Oh dear, something went wrong with stat()! %s", strerror(errno));
msg_format("Could not retrieve stats on the text file at {%s}", buf);
return (-1);
}
最让我烦恼的是文件在
~/git/hellband/lib/edit/r_info.txt
当我用打开文件的代码(使用相同的 buf)替换上面的代码,然后在文件描述符上使用 fstat() 时,它可以工作!!
我不想打开文件(记得关闭该文件),我只想知道/修复 stat() 的情况。
2020 年后记;结果是,当我使用 Angband 方法打开文件时,它会自动扩展 ~ 符号,这就是它起作用的原因,并且 fstat 起作用了。
【问题讨论】:
-
你得到了什么错误/errno?
-
文件或目录不存在。
-
请注意选民,我的问题足以得到正确的(接受!)答案。
-
没有细节,关于
fstat的短语非常令人困惑:打开文件的第一个想法 - 使用open- 会遇到与~相同的问题stat函数.请提供有关fstat案例的更多详细信息(即使用my_fopen打开文件)或完全删除此注释。并且最好将错误消息添加到 question post 本身。在目前的形式中,从问题帖子(没有 cmets!)中不清楚stat失败是因为它找不到文件。 -
@Tsyvarev 我认为你完全没有理解我的意思,对于像 P.P. 这样有经验的人来说。这个问题已经够好了。