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

在C中使用tmpfile()时的临时文件位置,第1张

概述$man tmpfile说 The standard does not specify the directory that tmpfile() will use. Glibc will try the path prefix P_tmpdir defined in <stdio.h>, and if that fails the

$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访问它.

总结

以上是内存溢出为你收集整理的在C中使用tmpfile()时的临时文件位置全部内容,希望文章能够帮你解决在C中使用tmpfile()时的临时文件位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1046993.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)