summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/libiberty/argv.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/binutils/libiberty/argv.c')
-rw-r--r--contrib/binutils/libiberty/argv.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/contrib/binutils/libiberty/argv.c b/contrib/binutils/libiberty/argv.c
index 11ca549..faeb72d 100644
--- a/contrib/binutils/libiberty/argv.c
+++ b/contrib/binutils/libiberty/argv.c
@@ -290,6 +290,61 @@ 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)
+ {
+ 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
@@ -312,9 +367,7 @@ operating system to free the memory when the program exits.
*/
void
-expandargv (argcp, argvp)
- int *argcp;
- char ***argvp;
+expandargv (int *argcp, char ***argvp)
{
/* The argument we are currently processing. */
int i = 0;
OpenPOWER on IntegriCloud