public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Yong <jyong@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3062] gcc.c-torture/execute: Fix tmpnam issue on Windows
Date: Mon, 23 Aug 2021 02:16:16 +0000 (GMT)	[thread overview]
Message-ID: <20210823021616.D9E2A3857C44@sourceware.org> (raw)

https://gcc.gnu.org/g:4a4616e53f440e15d0f3e91e23b67a3b5c84dddf

commit r12-3062-g4a4616e53f440e15d0f3e91e23b67a3b5c84dddf
Author: Jonathan Yong <10walls@gmail.com>
Date:   Sun Aug 22 03:05:07 2021 +0000

    gcc.c-torture/execute: Fix tmpnam issue on Windows
    
    2021-08-22  Jonathan Yong  <10walls@gmail.com>
    
    gcc/testsuite/ChangeLog:
    
            * gcc.c-torture/execute/gcc_tmpnam.h: Fix tmpnam case on Windows
            where it can return a filename with "\" to indicate current
            directory.
            * gcc.c-torture/execute/fprintf-2.c: Use wrapper.
            * gcc.c-torture/execute/printf-2.c: Use wrapper.
            * gcc.c-torture/execute/user-printf.c: Use wrapper.
    
    Signed-off-by: Jonathan Yong <10walls@gmail.com>

Diff:
---
 gcc/testsuite/gcc.c-torture/execute/fprintf-2.c   |  3 ++-
 gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h  | 13 +++++++++++++
 gcc/testsuite/gcc.c-torture/execute/printf-2.c    |  3 ++-
 gcc/testsuite/gcc.c-torture/execute/user-printf.c |  3 ++-
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
index d8e19e7b2f8..00517d1d1ac 100644
--- a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
@@ -9,10 +9,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "gcc_tmpnam.h"
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = fopen (tmpfname, "w");
   if (!f)
     {
diff --git a/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h b/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h
new file mode 100644
index 00000000000..2136e6eaf13
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h
@@ -0,0 +1,13 @@
+#include <stdio.h>
+#ifndef GCC_TMPNAM
+#define GCC_TMPNAM
+static inline char *gcc_tmpnam(char *s)
+{
+  char *ret = tmpnam (s);
+  // Windows sometimes prepends a backslash to denote the current directory,
+  // so swallow that if it occurs
+  if (ret[0] == '\\')
+    ++ret;
+  return ret;
+}
+#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/printf-2.c b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
index 4e7d8f7cdfa..2087bba8448 100644
--- a/gcc/testsuite/gcc.c-torture/execute/printf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "gcc_tmpnam.h"
 
 __attribute__ ((noipa)) void
 write_file (void)
@@ -26,7 +27,7 @@ write_file (void)
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = freopen (tmpfname, "w", stdout);
   if (!f)
     {
diff --git a/gcc/testsuite/gcc.c-torture/execute/user-printf.c b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
index 42a3b17f123..bfee0760dd7 100644
--- a/gcc/testsuite/gcc.c-torture/execute/user-printf.c
+++ b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "gcc_tmpnam.h"
 
 void __attribute__ ((format (printf, 1, 2), noipa))
 user_print (const char *fmt, ...)
@@ -23,7 +24,7 @@ user_print (const char *fmt, ...)
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = freopen (tmpfname, "w", stdout);
   if (!f)
     {


                 reply	other threads:[~2021-08-23  2:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210823021616.D9E2A3857C44@sourceware.org \
    --to=jyong@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).