/* Check system header files for ISO 9899:1990 (ISO C) compliance.
- Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jens Schweikhardt <schweikh@noc.dfn.de>, 1996.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License
- as published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
- The GNU C Library is distributed in the hope that it will be
- useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Library General Public License for more details.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If
- not, write to the Free Software Foundation, Inc., 59 Temple Place -
- Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
/* This is a simple minded program that tries to find illegal macro
definitions in system header files. Illegal macro definitions are
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.
# define _GNU_SOURCE 1
#endif
+#include <ctype.h>
#include <stdio.h>
#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[] =
{
"strtol", "strtoul", "strxfrm", "swprintf", "swscanf", "system",
"tan", "tanf", "tanh", "tanhf", "tanhl", "tanl", "time", "time_t",
"tmpfile", "tmpnam", "tolower", "toupper", "towctrans", "towlower",
- "towupper", "ungetc", "ungetwc", "va_arg", "va_end", "va_start",
+ "towupper", "ungetc", "ungetwc", "va_arg", "va_copy", "va_end", "va_start",
"vfprintf", "vfwprintf", "vprintf", "vsprintf", "vswprintf",
"vwprintf", "wchar_t", "wcrtomb", "wcscat", "wcschr", "wcscmp",
"wcscoll", "wcscpy", "wcscspn", "wcsftime", "wcslen", "wcsncat",
/* Format string to build command to invoke compiler. */
static const char fmt[] = "\
echo \"#include <%s>\" |\
-%s -E -dM -ansi -pedantic %s -D_LIBC -I. -I `%s --print-prog-name=include` -\
-> %s";
+%s -E -dM -ansi -pedantic %s -D_LIBC -D_ISOMAC \
+-DIN_MODULE=MODULE_extramodules -I. \
+-isystem `%s --print-prog-name=include` - 2> /dev/null > %s";
/* The compiler we use (given on the command line). */
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)
{
exit (1);
}
- sprintf (command, fmt, "/dev/null", CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, "/dev/null", CC, INC, CC, macrofile);
if (system (command))
{
puts ("system() returned nonzero");
+ free (command);
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;
}
start = &line[8];
for (end = start + 1; !isspace (*end) && *end != '\0'; ++end)
;
- result[result_len++] = xstrndup (start, end - start);
+ result[result_len] = xstrndup (start, end - start);
- if (first)
+ if (strcmp (result[result_len], "IN_MODULE") != 0)
{
- fputs ("The following identifiers will be ignored since the compiler defines them\nby default:\n", stdout);
- first = 0;
+ if (first)
+ {
+ fputs ("The following identifiers will be ignored since the compiler defines them\nby default:\n", stdout);
+ first = 0;
+ }
+ puts (result[result_len]);
}
- puts (result[result_len - 1]);
+ ++result_len;
}
if (result_len == result_max)
{
}
result[result_len] = NULL;
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
return (const char **) result;
}
int result = 0;
command = malloc (sizeof fmt + strlen (file_name) + 2 * strlen (CC)
- + strlen (INC) + strlen (TMPFILE));
+ + strlen (INC) + strlen (macrofile));
if (command == NULL)
{
}
puts (file_name);
- sprintf (command, fmt, file_name, CC, INC, CC, TMPFILE);
+ sprintf (command, fmt, file_name, CC, INC, CC, macrofile);
if (system (command))
{
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;
}
}
}
fclose (input);
- remove (TMPFILE);
+ remove (macrofile);
return result;
}