C ++ tmpnam替代 [英] C++ tmpnam alternative
问题描述
我有一个C ++库,使用 tmpnam(NULL)
创建一个临时文件。
I have a C++ library that uses tmpnam(NULL)
to create a temporary file.
hack这是因为它使临时文件在根文件夹(c:或/),因此它需要管理权限。
如何使用有效的临时路径来更改此函数?
I need to hack this because it makes the temp file in the root folder ("c:" or "/") and so it needs the administrative privileges. How can I change this function with other one using a valid temp path?
谢谢。
推荐答案
虽然 tmpnam
会返回由 /
表示当前目录中的唯一文件名,而不是 /
或 c:\
。因此,您可以在调用 tmpnam
之前为任何其他目录 chdir
找到该目录的唯一文件名。
Though tmpnam
returns a filename pre-pended by /
- it actually denotes a unique filename in the current directory and not /
or c:\
. So you can chdir
to any other directory before calling tmpnam
to find a unique filename for that directory.
您还可以调用 tempnam
而不是 tmpnam
作为输入。
You can also call tempnam
instead of tmpnam
which allows takes a directory name as input.
这篇关于C ++ tmpnam替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!