C++ tmpnam alternative

不问归期 提交于 2019-12-11 01:58:03

问题


I have a C++ library that uses tmpnam(NULL) to create a temporary file.

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?

Thanks.


回答1:


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.

You can also call tempnam instead of tmpnam which allows takes a directory name as input.



来源:https://stackoverflow.com/questions/18570517/c-tmpnam-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!