C ++ tmpnam替代 [英] C++ tmpnam alternative

查看:183
本文介绍了C ++ tmpnam替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆