add Filename::get_temp_directory()

This commit is contained in:
David Rose 2007-05-13 15:59:29 +00:00
parent 0329972a41
commit 9433628a0e
2 changed files with 45 additions and 0 deletions

View File

@ -51,6 +51,8 @@
#include <unistd.h>
#endif
bool Filename::_got_temp_directory;
Filename Filename::_temp_directory;
TypeHandle Filename::_type_handle;
#ifdef WIN32
@ -436,6 +438,44 @@ temporary(const string &dirname, const string &prefix, const string &suffix,
return result;
}
////////////////////////////////////////////////////////////////////
// Function: Filename::get_temp_directory
// Access: Published
// Description: Returns a path to a system-defined temporary
// directory.
////////////////////////////////////////////////////////////////////
const Filename &Filename::
get_temp_directory() {
if (!_got_temp_directory) {
#ifdef WIN32
static const size_t buffer_size = 4096;
char buffer[buffer_size];
if (GetTempPath(buffer_size, buffer) != 0) {
_temp_directory = from_os_specific(buffer);
if (_temp_directory.is_directory()) {
if (_temp_directory.make_canonical()) {
_got_temp_directory = true;
}
}
}
if (!_got_temp_directory) {
// if $TMP or $TEMP contain bogus strings, GetTempPath() may
// return a bogus string.
_temp_directory = ExecutionEnvironment::get_cwd();
_got_temp_directory = true;
}
#else
// Posix case.
_temp_directory = "/tmp";
_got_temp_directory = true;
#endif // WIN32
}
return _temp_directory;
}
////////////////////////////////////////////////////////////////////
// Function: Filename::set_fullpath
// Access: Published

View File

@ -87,6 +87,8 @@ PUBLISHED:
const string &suffix = string(),
Type type = T_general);
static const Filename &get_temp_directory();
// Assignment is via the = operator.
INLINE Filename &operator = (const string &filename);
INLINE Filename &operator = (const char *filename);
@ -218,6 +220,9 @@ protected:
int _flags;
static bool _got_temp_directory;
static Filename _temp_directory;
public:
static TypeHandle get_class_type() {
return _type_handle;