@@ -39,54 +39,55 @@ std::string get_temporary_directory(const std::string &name_template)
3939{
4040 std::string result;
4141
42- #ifdef _WIN32
43- (void )name_template; // unused parameter
44- DWORD dwBufSize = MAX_PATH+1 ;
45- char lpPathBuffer[MAX_PATH+1 ];
46- DWORD dwRetVal = GetTempPathA (dwBufSize, lpPathBuffer);
47-
48- if (dwRetVal > dwBufSize || (dwRetVal == 0 ))
49- {
50- throw system_exceptiont (" Couldn't get temporary path" );
51- }
52-
53- // GetTempFileNameA produces <path>\<pre><uuuu>.TMP
54- // where <pre> = "TLO"
55- // Thus, we must make the buffer 1+3+4+1+3=12 characters longer.
56-
57- char t[MAX_PATH];
58- UINT uRetVal=GetTempFileNameA (lpPathBuffer, " TLO" , 0 , t);
59- if (uRetVal == 0 )
60- {
61- throw system_exceptiont (
62- std::string (" Couldn't get new temporary file name in directory" ) +
63- lpPathBuffer);
64- }
65-
66- unlink (t);
67- if (_mkdir (t) != 0 )
68- {
69- throw system_exceptiont (
70- std::string (" Couldn't create temporary directory at " ) + t);
71- }
72- result=std::string (t);
73-
74- #else
75- std::string prefixed_name_template=" /tmp/" ;
76- const char *TMPDIR_env=getenv (" TMPDIR" );
77- if (TMPDIR_env!=nullptr )
78- prefixed_name_template=TMPDIR_env;
79- if (*prefixed_name_template.rbegin ()!=' /' )
80- prefixed_name_template+=' /' ;
81- prefixed_name_template+=name_template;
82-
83- std::vector<char > t (prefixed_name_template.begin (), prefixed_name_template.end ());
84- t.push_back (' \0 ' ); // add the zero
85- const char *td = mkdtemp (t.data ());
86- if (!td)
87- throw system_exceptiont (" Failed to create temporary directory" );
88- result=std::string (td);
89- #endif
42+ #ifdef _WIN32
43+ (void )name_template; // unused parameter
44+ DWORD dwBufSize = MAX_PATH + 1 ;
45+ char lpPathBuffer[MAX_PATH + 1 ];
46+ DWORD dwRetVal = GetTempPathA (dwBufSize, lpPathBuffer);
47+
48+ if (dwRetVal > dwBufSize || (dwRetVal == 0 ))
49+ {
50+ throw system_exceptiont (" Couldn't get temporary path" );
51+ }
52+
53+ // GetTempFileNameA produces <path>\<pre><uuuu>.TMP
54+ // where <pre> = "TLO"
55+ // Thus, we must make the buffer 1+3+4+1+3=12 characters longer.
56+
57+ char t[MAX_PATH];
58+ UINT uRetVal = GetTempFileNameA (lpPathBuffer, " TLO" , 0 , t);
59+ if (uRetVal == 0 )
60+ {
61+ throw system_exceptiont (
62+ std::string (" Couldn't get new temporary file name in directory" ) +
63+ lpPathBuffer);
64+ }
65+
66+ unlink (t);
67+ if (_mkdir (t) != 0 )
68+ {
69+ throw system_exceptiont (
70+ std::string (" Couldn't create temporary directory at " ) + t);
71+ }
72+ result = std::string (t);
73+
74+ #else
75+ std::string prefixed_name_template = " /tmp/" ;
76+ const char *TMPDIR_env = getenv (" TMPDIR" );
77+ if (TMPDIR_env != nullptr )
78+ prefixed_name_template = TMPDIR_env;
79+ if (*prefixed_name_template.rbegin () != ' /' )
80+ prefixed_name_template += ' /' ;
81+ prefixed_name_template += name_template;
82+
83+ std::vector<char > t (
84+ prefixed_name_template.begin (), prefixed_name_template.end ());
85+ t.push_back (' \0 ' ); // add the zero
86+ const char *td = mkdtemp (t.data ());
87+ if (!td)
88+ throw system_exceptiont (" Failed to create temporary directory" );
89+ result = std::string (td);
90+ #endif
9091
9192 return result;
9293}
0 commit comments