From 3d6a7aaa5be9ddb724ceb36efaca7b5c10036217 Mon Sep 17 00:00:00 2001 From: cpickett Date: Mon, 11 Feb 2013 22:59:48 +0000 Subject: [PATCH] * flip conditionals around in setup_pipe so that it's readable * call new open_tmp_file from setup_pipe instead of tmpfile, to make things work on WIN32, closing Bug 3314868 git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@701 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- src/check_msg.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/check_msg.c b/src/check_msg.c index cc44ff4..6fdcc79 100644 --- a/src/check_msg.c +++ b/src/check_msg.c @@ -183,15 +183,42 @@ void teardown_messaging(void) teardown_pipe(); } -static void setup_pipe(void) +static FILE * +open_tmp_file (void) { - if (send_file1 != 0) { - if (send_file2 != 0) - eprintf("Only one nesting of suite runs supported", __FILE__, __LINE__); - send_file2 = tmpfile(); - } else { - send_file1 = tmpfile(); - } + /* workaround from Bug 3314868, but maybe tmpfile works if TMPDIR is set */ + /* also note that mkstemp is apparently a C90 replacement for tmpfile */ + /* perhaps all we need to do on Windows is set TMPDIR to whatever is + stored in TEMP for tmpfile to work */ + /* 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_"); + file = fopen (tmp_file, "w+b"); + free (tmp_file); + } +#endif /* WIN32 */ + return file; +} + +static void +setup_pipe (void) +{ + if (send_file1 == NULL) + { + send_file1 = open_tmp_file (); + return; + } + if (send_file2 == NULL) + { + send_file2 = open_tmp_file (); + return; + } + eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__); } static void teardown_pipe(void) -- 2.40.0