From 0c18fee5b37f838c89b45c757deadfa81574e352 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 8 May 2007 01:29:33 +0000 Subject: [PATCH] merge from gcc --- include/ChangeLog | 4 ++++ include/libiberty.h | 4 ++++ libiberty/ChangeLog | 4 ++++ libiberty/argv.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/include/ChangeLog b/include/ChangeLog index 64e016e99f..297e8b36fb 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2007-05-07 Nathan Froyd + + * libiberty.h (writeargv): Declare. + 2007-04-30 Alan Modra * bfdlink.h (struct bfd_link_info): Add "info" and "minfo". diff --git a/include/libiberty.h b/include/libiberty.h index 7a58b711c3..4e697343fb 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -86,6 +86,10 @@ extern char **dupargv (char **) ATTRIBUTE_MALLOC; extern void expandargv PARAMS ((int *, char ***)); +/* Write argv to an @-file, inserting necessary quoting. */ + +extern int writeargv PARAMS ((char **, FILE *)); + /* Return the last component of a path name. Note that we can't use a prototype here because the parameter is declared inconsistently across different systems, sometimes as "char *" and sometimes as diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index c4e7072103..a4217845c7 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,7 @@ +2007-05-07 Nathan Froyd + + * argv.c (writeargv): New function. + 2007-05-05 Geoffrey Keating * cp-demangle.c (d_name): Detect local-source-name. diff --git a/libiberty/argv.c b/libiberty/argv.c index e76c1f825d..a04f50d7f4 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 -- 2.34.1