#include "webrtc/test/testsupport/fileutils.h"
+#include <assert.h>
+
#ifdef WIN32
#include <direct.h>
+#include <tchar.h>
+#include <windows.h>
#include <algorithm>
+
+#include "webrtc/system_wrappers/interface/utf_util_win.h"
#define GET_CURRENT_DIR _getcwd
#else
#include <unistd.h>
+
+#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#define GET_CURRENT_DIR getcwd
#endif
#endif
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "webrtc/typedefs.h" // For architecture defines
return kFallbackPath;
}
path += kOutputDirName;
- if (!CreateDirectory(path)) {
+ if (!CreateDir(path)) {
return kFallbackPath;
}
return path + kPathDelimiter;
#endif // !WEBRTC_ANDROID
-bool CreateDirectory(std::string directory_name) {
+// Generate a temporary filename in a safe way.
+// Largely copied from talk/base/{unixfilesystem,win32filesystem}.cc.
+std::string TempFilename(const std::string &dir, const std::string &prefix) {
+#ifdef WIN32
+ wchar_t filename[MAX_PATH];
+ if (::GetTempFileName(ToUtf16(dir).c_str(),
+ ToUtf16(prefix).c_str(), 0, filename) != 0)
+ return ToUtf8(filename);
+ assert(false);
+ return "";
+#else
+ int len = dir.size() + prefix.size() + 2 + 6;
+ scoped_ptr<char[]> tempname(new char[len]);
+
+ snprintf(tempname.get(), len, "%s/%sXXXXXX", dir.c_str(),
+ prefix.c_str());
+ int fd = ::mkstemp(tempname.get());
+ if (fd == -1) {
+ assert(false);
+ return "";
+ } else {
+ ::close(fd);
+ }
+ std::string ret(tempname.get());
+ return ret;
+#endif
+}
+
+bool CreateDir(std::string directory_name) {
struct stat path_info = {0};
// Check if the path exists already:
if (stat(directory_name.c_str(), &path_info) == 0) {