加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

在C中使用tmpfile()时的临时文件位置

发布时间:2020-12-13 19:05:43 所属栏目:Linux 来源:网络整理
导读:$man tmpfile说 The standard does not specify the directory that tmpfile() will use. Glibc will try the path prefix P_tmpdir defined in ,and if that fails the directory /tmp. 我使用的是Ubuntu 13.10 x86_64,gcc和libc BTW. 所以当我尝试使用tmpf

$man tmpfile说

The standard does not specify the directory that tmpfile() will use.
Glibc will try the path prefix P_tmpdir defined in ,and if
that fails the directory /tmp.

我使用的是Ubuntu 13.10 x86_64,gcc和libc BTW.

所以当我尝试使用tmpfile()创建临时文件时,我在/ tmp中看不到任何临时文件. (我可以在stdio.h中看到#define P_tmpdir“/ tmp”).这是我使用的代码片段:

#include 

$./tmpfile
现在,当scanf正在等待下一个(冗余)输入时,我应该能够在/ tmp中看到一个临时文件.但我不能.那么这个tmpfile到底在哪里创建?

最佳答案
可能直接删除目录中的文件条目.在POSIX系统上,只要您有一个打开的文件描述符,文件本身在删除后仍然有效. (在您的情况下隐藏在FILE *返回值中.)

使用这种技术,没有人可以潜入并打开该文件,只能通过变量tmp访问它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读