views:

257

answers:

4

I'm writing a function in C++ which creates a temporary directory. Such function should be as most portable as possible, e.g. it should work under linux, mac and win32 environments. How do I achieve that?

A: 

mkstemp(char *template)

http://www.cl.cam.ac.uk/cgi-bin/manpage?3+mkstemp

Paul Tomblin
+1  A: 

Check the mkdtemp function here.

This doesn't exist on Windows, as far as I know. :(
dauphic
I guess you are writer ... deleting ...
there is no platform independent way to do it in standard c/c++, use GetTempPath and GetTempFileName on Windows
Kane
A: 

There's no standard function to do this, so you'll need to compile different implementations for each platform you target.

On Windows, for example, you should use the temp directory, which can be obtained by a call to GetTempPath().

dauphic
+1  A: 

Boost's Filesystem library provides platform-independent directory functions. It will increase your program size a bit, but using Boost is often better (and often easier) than rolling your own.

http://www.boost.org/doc/libs/1_43_0/libs/filesystem/doc/index.htm

peachykeen
I don't want to introduce dependency on boost just for that.
Gatis