本文介绍了与boost :: filesystem :: unique_path()等效的C ++ 17是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: filesystem ,而许多C ++ 17之前的编译器的 std :: experimental :: filesystem ,均基于 boost :: filesystem ,几乎所有这些都可以移植到较新的std.

std::filesystem on C++17, and std::experimental::filesystem for many pre-C++17 compilers, are based on boost::filesystem and almost all of it is obvious to port to the newer std.

但是我看不到与 boost :: filesystem :: unique_path()等效的 std :: filesystem .

But I see no std::filesystem equivalent to boost::filesystem::unique_path().

std中有没有引起我注意的等效项吗?还是我应该采用一种推荐的方法来模仿实现?

Is there an equivalent in std that I'm not noticing? Or is there a recommended approach I should take to mimic the implementation?

当我的代码注意到它在支持 std :: filesystem 的平台上编译时,我真的希望替换 boost :: filesystem 依赖项unique_path()是我转换中唯一不明显的部分.

I'm really hoping to replace the boost::filesystem dependency when my code notices it's compiling on a platform that supports std::filesystem, and unique_path() is the only not obvious part of my conversion.

推荐答案

unique_path 已被删除,因为它是恶意软件的潜在攻击媒介.在调用 unique_path 和在该位置打开文件之间存在一个机会之窗,在此期间其他一些过程可以创建相同的文件.根据用户对文件的处理方式,这可能会或可能不会构成安全漏洞.POSIX函数 tmpnam .

unique_path was removed because it was a potential attack vector for malware. There is a window of opportunity between calling unique_path and opening a file at that location during which some other process could create the same file. Depending on what the user does with the file, this may or may not constitute a security vulnerability. A similar issue exists with the POSIX function tmpnam.

此讨论所述,该问题将在下一版的文件系统库.在此之前,您可以继续使用 Boost.Filesystem ,使用 std :: tmpnam < cstdio> 中提供的功能,或者使用更安全的平台特定替代方案,例如 mkstemp .

As noted in this discussion, this issue will be dealt with in the next iteration of the Filesystem library. Until then, you can either continue using Boost.Filesystem, use the std::tmpnam function provided in <cstdio>, or use safer platform-specific alternatives like mkstemp.

这篇关于与boost :: filesystem :: unique_path()等效的C ++ 17是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:52