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>
#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)
{
--- /dev/null
+#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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "gcc_tmpnam.h"
__attribute__ ((noipa)) void
write_file (void)
int main (void)
{
- char *tmpfname = tmpnam (0);
+ char *tmpfname = gcc_tmpnam (0);
FILE *f = freopen (tmpfname, "w", stdout);
if (!f)
{
#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, ...)
int main (void)
{
- char *tmpfname = tmpnam (0);
+ char *tmpfname = gcc_tmpnam (0);
FILE *f = freopen (tmpfname, "w", stdout);
if (!f)
{