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>
This commit is contained in:
Jonathan Yong 2021-08-22 03:05:07 +00:00
parent 5b2876f96c
commit 4a4616e53f
4 changed files with 19 additions and 3 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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)
{

View File

@ -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)
{