]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdlib/isomac.c
hurd: Fix build
[thirdparty/glibc.git] / stdlib / isomac.c
index 47040e61e6af11143aa9ee4c1eecff8a383b5f3c..8abf93185b2fadf384f4c796a5ee36a608648e8a 100644 (file)
@@ -1,22 +1,21 @@
 /* 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
@@ -52,7 +51,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.
 
 # 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[] =
 {
@@ -156,7 +157,7 @@ static char *macros[] =
   "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",
@@ -176,8 +177,9 @@ static char *macros[] =
 /* 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).  */
@@ -247,8 +249,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,19 +260,20 @@ 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))
     {
       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;
     }
@@ -300,14 +305,18 @@ get_null_defines (void)
       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)
     {
@@ -321,7 +330,7 @@ get_null_defines (void)
     }
   result[result_len] = NULL;
   fclose (input);
-  remove (TMPFILE);
+  remove (macrofile);
 
   return (const char **) result;
 }
@@ -335,7 +344,7 @@ check_header (const char *file_name, const char **except)
   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 +353,7 @@ check_header (const char *file_name, const char **except)
     }
 
   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 +361,11 @@ check_header (const char *file_name, const char **except)
       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 +439,7 @@ check_header (const char *file_name, const char **except)
        }
     }
   fclose (input);
-  remove (TMPFILE);
+  remove (macrofile);
 
   return result;
 }