A patch for stdlib/isomac.c
H . J . Lu
hjl@lucon.org
Sun Apr 1 10:19:00 GMT 2001
On Sun, Apr 01, 2001 at 10:11:06AM -0700, Ulrich Drepper wrote:
> "H . J . Lu" <hjl@lucon.org> writes:
>
> > 2001-04-01 H.J. Lu <hjl@gnu.org>
> >
> > * posix/annexc.c (TMPFILE): Change it to tmpnam (NULL).
> > * stdlib/isomac.c (TMPFILE): Likewise.
>
> There is no reason to keep the old macro definition and while you're
> at it name the variables like a variable (i.e., not in upper-case).
>
Here is a new one.
H.J.
---
2001-04-01 H.J. Lu <hjl@gnu.org>
* posix/annexc.c (macrofile): Renamed from TMPFILE and set to
tmpnam (NULL).
* stdlib/isomac.c (macrofile): Likewise.
Index: posix/annexc.c
===================================================================
RCS file: /work/cvs/gnu/glibc/posix/annexc.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 annexc.c
--- posix/annexc.c 2000/08/27 22:48:06 1.1.1.2
+++ posix/annexc.c 2001/04/01 17:16:00
@@ -25,9 +25,10 @@
#include <signal.h>
#include <sys/wait.h>
-#define TMPFILE "/tmp/macros"
#define HEADER_MAX 256
+static const char *macrofile;
+
/* <aio.h>. */
static const char *const aio_syms[] =
{
@@ -712,8 +713,10 @@ get_null_defines (void)
FILE *input;
int first = 1;
+ macrofile = tmpnam (NULL);
+
command = malloc (sizeof fmt + sizeof "/dev/null" + 2 * strlen (CC)
- + strlen (INC) + strlen (TMPFILE));
+ + strlen (INC) + strlen (macrofile));
if (command == NULL)
{
@@ -721,7 +724,7 @@ get_null_defines (void)
exit (1);
}
- sprintf (command, fmt, "/dev/null", CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, "/dev/null", CC, INC, CC, macrofile);
if (xsystem (command))
{
@@ -729,11 +732,11 @@ get_null_defines (void)
return NULL;
}
free (command);
- input = fopen (TMPFILE, "r");
+ input = fopen (macrofile, "r");
if (input == NULL)
{
- printf ("Could not read %s: ", TMPFILE);
+ printf ("Could not read %s: ", macrofile);
perror (NULL);
return NULL;
}
@@ -782,7 +785,7 @@ get_null_defines (void)
}
result[result_len] = NULL;
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
return (const char **) result;
}
@@ -799,7 +802,7 @@ check_header (const struct header *heade
memset (found, '\0', header->nsyms * sizeof (int));
command = alloca (sizeof fmt + strlen (header->name) + 2 * strlen (CC)
- + strlen (INC) + strlen (TMPFILE));
+ + strlen (INC) + strlen (macrofile));
if (command == NULL)
@@ -809,13 +812,13 @@ check_header (const struct header *heade
}
printf ("=== %s ===\n", header->name);
- sprintf (command, fmt, header->name, CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, header->name, CC, INC, CC, macrofile);
/* First see whether this subset is supported at all. */
if (header->subset != NULL)
{
sprintf (line, testfmt, header->subset, header->subset, CC, INC, CC,
- TMPFILE);
+ macrofile);
if (xsystem (line))
{
printf ("!! not available\n");
@@ -828,11 +831,11 @@ check_header (const struct header *heade
puts ("system() returned nonzero");
result = 1;
}
- input = fopen (TMPFILE, "r");
+ input = fopen (macrofile, "r");
if (input == NULL)
{
- printf ("Could not read %s: ", TMPFILE);
+ printf ("Could not read %s: ", macrofile);
perror (NULL);
return 1;
}
@@ -884,7 +887,7 @@ check_header (const struct header *heade
result |= 1;
}
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
for (i = 0; i < header->nsyms; ++i)
if (found[i] == 0)
Index: stdlib/isomac.c
===================================================================
RCS file: /work/cvs/gnu/glibc/stdlib/isomac.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 isomac.c
--- stdlib/isomac.c 2001/04/01 03:53:20 1.1.1.2
+++ stdlib/isomac.c 2001/04/01 17:16:55
@@ -52,7 +52,7 @@
preprocessor has something similar to gcc's -dM option. Tune
PRINT_MACROS in this case. This program assumes headers are found
under /usr/include and that there is a writable /tmp directory.
- Tune SYSTEM_INCLUDE and TMPFILE if your system differs.
+ Tune SYSTEM_INCLUDE if your system differs.
#define BROKEN_SYSTEM if system(NULL) bombs -- one more violation
of ISO C, by the way.
@@ -75,9 +75,10 @@
#include <stdlib.h>
#include <string.h>
-#define TMPFILE "/tmp/macros"
#define HEADER_MAX 256
+static const char *macrofile;
+
/* ISO C header names including Amendment 1 (without ".h" suffix). */
static char *header[] =
{
@@ -247,8 +248,10 @@ get_null_defines (void)
FILE *input;
int first = 1;
+ macrofile = tmpnam (NULL);
+
command = malloc (sizeof fmt + sizeof "/dev/null" + 2 * strlen (CC)
- + strlen (INC) + strlen (TMPFILE));
+ + strlen (INC) + strlen (macrofile));
if (command == NULL)
{
@@ -256,7 +259,7 @@ get_null_defines (void)
exit (1);
}
- sprintf (command, fmt, "/dev/null", CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, "/dev/null", CC, INC, CC, macrofile);
if (system (command))
{
@@ -264,11 +267,11 @@ get_null_defines (void)
return NULL;
}
free (command);
- input = fopen (TMPFILE, "r");
+ input = fopen (macrofile, "r");
if (input == NULL)
{
- printf ("Could not read %s: ", TMPFILE);
+ printf ("Could not read %s: ", macrofile);
perror (NULL);
return NULL;
}
@@ -321,7 +324,7 @@ get_null_defines (void)
}
result[result_len] = NULL;
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
return (const char **) result;
}
@@ -335,7 +338,7 @@ check_header (const char *file_name, con
int result = 0;
command = malloc (sizeof fmt + strlen (file_name) + 2 * strlen (CC)
- + strlen (INC) + strlen (TMPFILE));
+ + strlen (INC) + strlen (macrofile));
if (command == NULL)
{
@@ -344,7 +347,7 @@ check_header (const char *file_name, con
}
puts (file_name);
- sprintf (command, fmt, file_name, CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, file_name, CC, INC, CC, macrofile);
if (system (command))
{
@@ -352,11 +355,11 @@ check_header (const char *file_name, con
result = 1;
}
free (command);
- input = fopen (TMPFILE, "r");
+ input = fopen (macrofile, "r");
if (input == NULL)
{
- printf ("Could not read %s: ", TMPFILE);
+ printf ("Could not read %s: ", macrofile);
perror (NULL);
return 1;
}
@@ -430,7 +433,7 @@ check_header (const char *file_name, con
}
}
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
return result;
}
More information about the Libc-alpha
mailing list