merge from gcc
authorDJ Delorie <dj@redhat.com>
Tue, 8 May 2007 01:29:33 +0000 (01:29 +0000)
committerDJ Delorie <dj@redhat.com>
Tue, 8 May 2007 01:29:33 +0000 (01:29 +0000)
include/ChangeLog
include/libiberty.h
libiberty/ChangeLog
libiberty/argv.c

index 64e016e99fb9bbebab46cc959e81f1900f798de2..297e8b36fb3a7e6b18a0f25f0537e097dabf8401 100644 (file)
@@ -1,3 +1,7 @@
+2007-05-07  Nathan Froyd  <froydnj@codesourcery.com>
+
+       * libiberty.h (writeargv): Declare.
+
 2007-04-30  Alan Modra  <amodra@bigpond.net.au>
 
        * bfdlink.h (struct bfd_link_info): Add "info" and "minfo".
index 7a58b711c37df383e3a6bf6b5f91b09bd40f49dc..4e697343fb6f9095f41e9d4da1d343b4c6342c26 100644 (file)
@@ -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
index c4e707210369df89070e502b39110a664660aabc..a4217845c7359f996917f257c4c504cae2ea2558 100644 (file)
@@ -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.
index e76c1f825d26cb1c2f111f1585222cb6bafaa6bd..a04f50d7f4910a02666a81d71317a6f4692dfca3 100644 (file)
@@ -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
This page took 0.059568 seconds and 4 git commands to generate.