From bbfae0cc673d3abdc21224c53e09b209ee4688a2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 9 Sep 2021 16:51:35 +0200 Subject: Dynamic_Add_Media v2 (#11550) --- src/filesys.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/filesys.cpp') diff --git a/src/filesys.cpp b/src/filesys.cpp index 99b030624..0941739b8 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -21,8 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include #include +#include #include #include +#include #include #include "log.h" #include "config.h" @@ -811,5 +813,15 @@ bool Rename(const std::string &from, const std::string &to) return rename(from.c_str(), to.c_str()) == 0; } +std::string CreateTempFile() +{ + std::string path = TempPath() + DIR_DELIM "MT_XXXXXX"; + int fd = mkstemp(&path[0]); // modifies path + if (fd == -1) + return ""; + close(fd); + return path; +} + } // namespace fs -- cgit v1.2.3 From 4feb799b7e33c1a544036a830faf00eb33d3eaf5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 13 Sep 2021 19:40:53 +0200 Subject: Add Windows-specific CreateTempFile() implementation Once again MSVC is the only compiler not supporting basic POSIX functionality. --- src/filesys.cpp | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/filesys.cpp') diff --git a/src/filesys.cpp b/src/filesys.cpp index 0941739b8..a07370c0e 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include #include #include "log.h" #include "config.h" @@ -38,6 +37,7 @@ namespace fs #define _WIN32_WINNT 0x0501 #include #include +#include std::vector GetDirListing(const std::string &pathstring) { @@ -178,13 +178,27 @@ std::string TempPath() errorstream<<"GetTempPath failed, error = "< buf(bufsize); + std::string buf; + buf.resize(bufsize); DWORD len = GetTempPath(bufsize, &buf[0]); if(len == 0 || len > bufsize){ errorstream<<"GetTempPath failed, error = "< &dirs, const std::string &dir) @@ -813,15 +837,5 @@ bool Rename(const std::string &from, const std::string &to) return rename(from.c_str(), to.c_str()) == 0; } -std::string CreateTempFile() -{ - std::string path = TempPath() + DIR_DELIM "MT_XXXXXX"; - int fd = mkstemp(&path[0]); // modifies path - if (fd == -1) - return ""; - close(fd); - return path; -} - } // namespace fs -- cgit v1.2.3