Remove use of tmpnam.
This solves compilation with the Mac SDK 10.9.
BUG=3120, 3151
TEST=git try -t modules_tests:VideoProcessorIntegrationTest*
R=fischman@webrtc.org, henrike@webrtc.org, stefan@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/10739005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5917 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc
index c89f9bd..9d04ab0 100644
--- a/webrtc/test/testsupport/fileutils.cc
+++ b/webrtc/test/testsupport/fileutils.cc
@@ -11,11 +11,18 @@
#include "webrtc/test/testsupport/fileutils.h"
#ifdef WIN32
+#include <assert.h>
#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
@@ -25,6 +32,7 @@
#endif
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "webrtc/typedefs.h" // For architecture defines
@@ -92,7 +100,7 @@
return kFallbackPath;
}
path += kOutputDirName;
- if (!CreateDirectory(path)) {
+ if (!CreateDir(path)) {
return kFallbackPath;
}
return path + kPathDelimiter;
@@ -154,7 +162,35 @@
#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) {