]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/file.cpp
GetTempFileName used in wxTempFile now instead of tmpnam
[wxWidgets.git] / src / common / file.cpp
index 05e18e8866ae12e87d9a910effc6d7a5aa3cc356..d4a0e135511dc44c9feba92b6c4f8fcc47b1bbbe 100644 (file)
 // standard
 #if    defined(__WXMSW__) && !defined(__GNUWIN32__)
   #include  <io.h>
+
+  #define   WIN32_LEAN_AND_MEAN
+  #define   NOSERVICE
+  #define   NOIME
+  #define   NOATOM
+  #define   NOGDI
+  #define   NOGDICAPMASKS
+  #define   NOMETAFILE
+  #define   NOMINMAX
+  #define   NOMSG
+  #define   NOOPENFILE
+  #define   NORASTEROPS
+  #define   NOSCROLL
+  #define   NOSOUND
+  #define   NOSYSMETRICS
+  #define   NOTEXTMETRIC
+  #define   NOWH
+  #define   NOCOMM
+  #define   NOKANJI
+  #define   NOCRYPT
+  #define   NOMCX
+  #include  <windows.h>     // for GetTempFileName
 #elif (defined(__UNIX__) || defined(__GNUWIN32__))
   #include  <unistd.h>
 #else
@@ -376,10 +398,15 @@ bool wxTempFile::Open(const wxString& strName)
   #ifdef  __UNIX__
     static const char *szMktempSuffix = "XXXXXX";
     m_strTemp << strName << szMktempSuffix;
-    mktemp((char *)m_strTemp.c_str()); // @@@ even if the length doesn't change
-    //m_strTemp.UngetWriteBuf();
+    mktemp((char *)m_strTemp.c_str()); // will do because length doesn't change
   #else // Windows
-    m_strTemp = tmpnam(NULL);
+    wxString strPath;
+    wxSplitPath(strName, &strPath, NULL, NULL);
+    if ( strPath.IsEmpty() )
+      strPath = '.';  // GetTempFileName will fail if we give it empty string
+    if ( !GetTempFileName(strPath, "wx_",0, m_strTemp.GetWriteBuf(MAX_PATH)) )
+      wxLogLastError("GetTempFileName");
+    m_strTemp.UngetWriteBuf();
   #endif  // Windows/Unix
     
   return m_file.Open(m_strTemp, wxFile::write);