@@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
24
24
#include < cstdlib>
25
25
#include < cstring>
26
26
#include < cerrno>
27
- #include < unistd.h>
28
27
#include < fstream>
29
28
#include " log.h"
30
29
#include " config.h"
@@ -38,6 +37,7 @@ namespace fs
38
37
#define _WIN32_WINNT 0x0501
39
38
#include < windows.h>
40
39
#include < shlwapi.h>
40
+ #include < io.h>
41
41
42
42
std::vector<DirListNode> GetDirListing (const std::string &pathstring)
43
43
{
@@ -178,13 +178,27 @@ std::string TempPath()
178
178
errorstream<<" GetTempPath failed, error = " <<GetLastError ()<<std::endl;
179
179
return " " ;
180
180
}
181
- std::vector<char > buf (bufsize);
181
+ std::string buf;
182
+ buf.resize (bufsize);
182
183
DWORD len = GetTempPath (bufsize, &buf[0 ]);
183
184
if (len == 0 || len > bufsize){
184
185
errorstream<<" GetTempPath failed, error = " <<GetLastError ()<<std::endl;
185
186
return " " ;
186
187
}
187
- return std::string (buf.begin (), buf.begin () + len);
188
+ buf.resize (len);
189
+ return buf;
190
+ }
191
+
192
+ std::string CreateTempFile ()
193
+ {
194
+ std::string path = TempPath () + DIR_DELIM " MT_XXXXXX" ;
195
+ _mktemp_s (&path[0 ], path.size () + 1 ); // modifies path
196
+ HANDLE file = CreateFile (path.c_str (), GENERIC_WRITE, 0 , nullptr ,
197
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr );
198
+ if (file == INVALID_HANDLE_VALUE)
199
+ return " " ;
200
+ CloseHandle (file);
201
+ return path;
188
202
}
189
203
190
204
#else // POSIX
@@ -366,6 +380,16 @@ std::string TempPath()
366
380
#endif
367
381
}
368
382
383
+ std::string CreateTempFile ()
384
+ {
385
+ std::string path = TempPath () + DIR_DELIM " MT_XXXXXX" ;
386
+ int fd = mkstemp (&path[0 ]); // modifies path
387
+ if (fd == -1 )
388
+ return " " ;
389
+ close (fd);
390
+ return path;
391
+ }
392
+
369
393
#endif
370
394
371
395
void GetRecursiveDirs (std::vector<std::string> &dirs, const std::string &dir)
@@ -813,15 +837,5 @@ bool Rename(const std::string &from, const std::string &to)
813
837
return rename (from.c_str (), to.c_str ()) == 0 ;
814
838
}
815
839
816
- std::string CreateTempFile ()
817
- {
818
- std::string path = TempPath () + DIR_DELIM " MT_XXXXXX" ;
819
- int fd = mkstemp (&path[0 ]); // modifies path
820
- if (fd == -1 )
821
- return " " ;
822
- close (fd);
823
- return path;
824
- }
825
-
826
840
} // namespace fs
827
841
0 commit comments