diff options
author | Nathan Froyd <froydnj@gcc.gnu.org> | 2007-05-08 00:37:39 +0000 |
---|---|---|
committer | Nathan Froyd <froydnj@gcc.gnu.org> | 2007-05-08 00:37:39 +0000 |
commit | 2091ff6689ae73c4b95338a435d1c6e7b743599e (patch) | |
tree | 3aff327d968d66aedb2dcdc719740c083d117e18 /libiberty/argv.c | |
parent | decc7c8a1cd784b2edeff50ee0f30572237b71f6 (diff) | |
download | gcc-2091ff6689ae73c4b95338a435d1c6e7b743599e.zip gcc-2091ff6689ae73c4b95338a435d1c6e7b743599e.tar.gz gcc-2091ff6689ae73c4b95338a435d1c6e7b743599e.tar.bz2 |
libiberty.h (writeargv): Declare.
include/
2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
* libiberty.h (writeargv): Declare.
libiberty/
2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
* argv.c (writeargv): New function.
gcc/
2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
* gcc.c (at_file_supplied): New variable.
(main): Set it if we expanded argv.
(do_spec_1): Pass an @-file to the linker if we were called with
an @-file argument and HAVE_GNU_LD.
* collect2.c (at_file_supplied): New variable.
(response_file): New variable.
(collect_exit): Unlink response_file if necessary.
(handler): Likewise.
(do_wait): Likewise.
(main): Set at_file_supplied if we expanded argv.
(collect_execute): Pass an @-file to subprocesses if we were called
with an @-file argument.
* configure.ac: Add define for HAVE_GNU_LD.
* configure: Regenerate.
* config.in: Regenerate.
From-SVN: r124532
Diffstat (limited to 'libiberty/argv.c')
-rw-r--r-- | libiberty/argv.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libiberty/argv.c b/libiberty/argv.c index e76c1f8..a04f50d 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -290,6 +290,62 @@ char **buildargv (const char *input) /* +@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@{file}) + +Write each member of ARGV, handling all necessary quoting, to the file +named by FILE, separated by whitespace. Return 0 on success, non-zero +if an error occurred while writing to FILE. + +@end deftypefn + +*/ + +int +writeargv (char **argv, FILE *f) +{ + int status = 0; + + if (f == NULL) + return 1; + + while (*argv != NULL) + { + int ret; + const char *arg = *argv; + + while (*arg != EOS) + { + char c = *arg; + + if (ISSPACE(c) || c == '\\' || c == '\'' || c == '"') + if (EOF == fputc ('\\', f)) + { + status = 1; + goto done; + } + + if (EOF == fputc (c, f)) + { + status = 1; + goto done; + } + arg++; + } + + if (EOF == fputc ('\n', f)) + { + status = 1; + goto done; + } + argv++; + } + + done: + return status; +} + +/* + @deftypefn Extension void expandargv (int *@var{argcp}, char ***@var{argvp}) The @var{argcp} and @code{argvp} arguments are pointers to the usual |