summaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2007-05-08 01:29:33 +0000
committerDJ Delorie <dj@delorie.com>2007-05-08 01:29:33 +0000
commitcd25b663c093ba6f5c944e40e53fddced55e8ce2 (patch)
treefb90a60e3e59648b997a0fedd3ba5faee6039293 /libiberty
parentb023334986f31c5c97a528d61a276c89fdebcdc4 (diff)
downloadgdb-cd25b663c093ba6f5c944e40e53fddced55e8ce2.tar.gz
merge from gcc
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog4
-rw-r--r--libiberty/argv.c56
2 files changed, 60 insertions, 0 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index c4e70721036..a4217845c73 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,7 @@
+2007-05-07 Nathan Froyd <froydnj@codesourcery.com>
+
+ * argv.c (writeargv): New function.
+
2007-05-05 Geoffrey Keating <geoffk@apple.com>
* cp-demangle.c (d_name): Detect local-source-name.
diff --git a/libiberty/argv.c b/libiberty/argv.c
index e76c1f825d2..a04f50d7f49 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