* gdb.texinfo (C Operators): Remove incorrect parenthetical comment
[deliverable/binutils-gdb.git] / binutils / resrc.c
index 2b148efc8cd85d63a94a409e7936afe13c1535b2..8a5900bdc489bc86041cfd5898b3a3ee733ea8d7 100644 (file)
@@ -8,7 +8,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -436,41 +436,48 @@ read_rc_file (const char *filename, const char *preprocessor,
   char *cmd;
   const char *fnquotes = (filename_need_quotes (filename) ? "\"" : "");
 
+  if (filename == NULL)
+    filename = "-";
   /* Setup the default resource import path taken from input file.  */
-  if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
+  else if (strchr (filename, '/') != NULL || strchr (filename, '\\') != NULL)
     {
-      char *e, *c;
+      char *edit, *dir;
 
       if (filename[0] == '/'
          || filename[0] == '\\'
          || filename[1] == ':')
-       e = c = xstrdup (filename);
+        /* Absolute path.  */
+       edit = dir = xstrdup (filename);
       else
        {
-         e = c = xmalloc (strlen (filename) + 3);
-         sprintf (c, "./%s", filename);
+         /* Relative path.  */
+         edit = dir = xmalloc (strlen (filename) + 3);
+         sprintf (dir, "./%s", filename);
        }
-      e += strlen (c);
-      while (e > c && (e[-1] != '\\' && e[-1] != '/'))
+
+      /* Walk dir backwards stopping at the first directory separator.  */
+      edit += strlen (dir);
+      while (edit > dir && (edit[-1] != '\\' && edit[-1] != '/'))
        {
-         --e;
-         e[0] = 0;
+         --edit;
+         edit[0] = 0;
        }
+
       /* Cut off trailing slash.  */
-      --e;
-      e[0] = 0;
-      while ((e = strchr (c, '\\')) != NULL)
-       *e = '/';
+      --edit;
+      edit[0] = 0;
+
+      /* Convert all back slashes to forward slashes.  */
+      while ((edit = strchr (dir, '\\')) != NULL)
+       *edit = '/';
 
-      windres_add_include_dir (e);
+      windres_add_include_dir (dir);
     }
 
   istream_type = (use_temp_file) ? ISTREAM_FILE : ISTREAM_PIPE;
 
   if (preprocargs == NULL)
     preprocargs = "";
-  if (filename == NULL)
-    filename = "-";
 
   if (preprocessor)
     {
@@ -588,7 +595,19 @@ close_input_stream (void)
   else
     {
       if (cpp_pipe != NULL)
-       pclose (cpp_pipe);
+        {
+         int err;
+         err = pclose (cpp_pipe);
+         /* We are reading from a pipe, therefore we don't
+             know if cpp failed or succeeded until pclose.  */
+         if (err != 0 || errno == ECHILD)
+           {
+             /* Since this is also run via xatexit, safeguard.  */
+             cpp_pipe = NULL;
+             cpp_temp_file = NULL;
+             fatal (_("preprocessing failed."));
+           }
+        }
     }
 
   /* Since this is also run via xatexit, safeguard.  */
This page took 0.026268 seconds and 4 git commands to generate.