9 # include <vcl_msvc_warnings.h> 12 #if defined (_MSC_VER) || defined(__MINGW32__) 16 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__) 25 bool is_okay(
const std::string& name )
28 int fd = open( name.c_str(), O_CREAT|O_EXCL, 0600 );
32 unlink( name.c_str() );
44 std::srand( std::time(
nullptr ) );
47 static int random_seed_trigger = init_randomizer();
52 int r = std::rand() % (26+26);
53 return (r<26) ? char(
'A'+r) : char(
'a'+r-26);
59 int r = std::rand() % (26+26+10);
60 return (r<26) ? char(
'A'+r) : (r<52) ? char(
'a'+r-26) : char(
'0'+r-52);
64 # warning "This is neither unix nor MS-windows - please add specifics to " __FILE__ 71 #if defined(_MSC_VER) || defined(__MINGW32__) 72 char path[ _MAX_PATH ];
74 if ( GetTempPath( _MAX_PATH, path ) == 0 )
81 file = _tempnam( path,
"" );
86 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__) 89 const unsigned int num_char_in_filename = 7+1;
92 unsigned int count = 0;
95 if ( std::getenv(
"TMP" ) ) {
96 tempdir = std::getenv(
"TMP" );
100 char lastchar = ( tempdir.size() > 0 ) ? tempdir[tempdir.size()-1] :
' ';
101 if (lastchar !=
'/' && lastchar !=
'\\')
104 while ( !okay && count < 10 ) {
105 char buf[ num_char_in_filename+1 ];
106 buf[0] = random_letter();
107 for (
unsigned int i=1; i < num_char_in_filename; ++i )
108 buf[i] = random_char();
109 buf[num_char_in_filename] =
'\0';
110 filename = tempdir + buf;
112 okay = is_okay( filename );
120 # warning "This is neither unix nor MS-windows - please add specifics to " __FILE__ Generates a temporary filename.
std::string vul_temp_filename()
Generates a temporary filename.