diff options
author | Carlos O'Donell <carlos@codesourcery.com> | 2007-10-08 13:50:18 +0000 |
---|---|---|
committer | Carlos O'Donell <carlos@codesourcery.com> | 2007-10-08 13:50:18 +0000 |
commit | c7f0a8e098119312e57c77969a0c6646abfd2040 (patch) | |
tree | d7755aeb4d8a12a760dde577e4aa78eeb40cf0a5 /binutils | |
parent | 313628ccbab4a2f66be351ba65a0734e75e3448f (diff) | |
download | gdb-c7f0a8e098119312e57c77969a0c6646abfd2040.zip gdb-c7f0a8e098119312e57c77969a0c6646abfd2040.tar.gz gdb-c7f0a8e098119312e57c77969a0c6646abfd2040.tar.bz2 |
2007-10-08 Carlos O'Donell <carlos@codesourcery.com>
* resrc.c (read_rc_file): Rename e to edit, and c to dir.
Pass dir to windres_add_include_dir. Add comments.
(close_input_stream): Check pclose error, and call fatal if
the preprocessor failed.
* windres.c (windres_add_include_dir): Assert that p is non-NULL,
and not an empty string.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/resrc.c | 47 | ||||
-rw-r--r-- | binutils/windres.c | 6 |
2 files changed, 39 insertions, 14 deletions
diff --git a/binutils/resrc.c b/binutils/resrc.c index a621319..8a5900b 100644 --- a/binutils/resrc.c +++ b/binutils/resrc.c @@ -441,30 +441,37 @@ read_rc_file (const char *filename, const char *preprocessor, /* Setup the default resource import path taken from input file. */ 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; - windres_add_include_dir (e); + /* Convert all back slashes to forward slashes. */ + while ((edit = strchr (dir, '\\')) != NULL) + *edit = '/'; + + windres_add_include_dir (dir); } istream_type = (use_temp_file) ? ISTREAM_FILE : ISTREAM_PIPE; @@ -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. */ diff --git a/binutils/windres.c b/binutils/windres.c index ac643ad..a4b466c 100644 --- a/binutils/windres.c +++ b/binutils/windres.c @@ -765,6 +765,12 @@ windres_add_include_dir (const char *p) { struct include_dir *n, **pp; + /* Computing paths is often complicated and error prone. + The easiest way to check for mistakes is at the time + we add them to include_dirs. */ + assert (p != NULL); + assert (*p != '\0'); + n = xmalloc (sizeof *n); n->next = NULL; n->dir = (char * ) p; |