问题
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