]> granicus.if.org Git - check/commitdiff
Always try alternative to tmpfile() if necessary
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 21 Sep 2013 16:03:14 +0000 (16:03 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Sat, 21 Sep 2013 16:03:14 +0000 (16:03 +0000)
If tmpfile fails on a platform, there is no harm in trying the
alternative.

Previously the alternative was only attempted for Windows. However,
checking for WIN32 was not correct; instead _WIN32 should be used.
When the proper check for Windows was attempted, OSX would fail
to run its tests. However, removing the conditional and renaming
_tempnam to tempnam (which is available in MinGW, OSX, and GNU/Linux)
works for all three platforms.

Correctly check for Windows environment

The correct way to check for compiling for Windows is to check for
_WIN32 instead of WIN32.

Patch submitted by username bross on Sourceforge, patch#48

git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@756 64e312b2-a51f-0410-8e61-82d0ca0eb02a

src/check_msg.c

index 6fdcc79311f63699e3114ba1302dbc30ec53b52a..3d3fcb438b57af8d8559486a0c3a3edd984e50c2 100644 (file)
@@ -193,15 +193,13 @@ open_tmp_file (void)
   /* it's also not clear if we need _tempnam instead of tempnam on WIN32 */
   /* and finally, the "b" from "w+b" is ignored on OS X, not sure about WIN32 */
   FILE *file = tmpfile ();
-#ifdef WIN32
   if (file == NULL)
     {
       char *tmp = getenv ("TEMP");
-      char *tmp_file = _tempnam (tmp, "check_");
+      char *tmp_file = tempnam (tmp, "check_");
       file = fopen (tmp_file, "w+b");
       free (tmp_file);
     }
-#endif /* WIN32 */
   return file;
 }