diff options
author | DJ Delorie <dj@redhat.com> | 2007-05-08 01:29:33 +0000 |
---|---|---|
committer | DJ Delorie <dj@redhat.com> | 2007-05-08 01:29:33 +0000 |
commit | 0c18fee5b37f838c89b45c757deadfa81574e352 (patch) | |
tree | 84771eb0a6a707e0a63e712f7602dbc8d2d8cd0b /libiberty/argv.c | |
parent | f453a23a5117037dd9f787e5cf8796cdf91d75d0 (diff) | |
download | binutils-0c18fee5b37f838c89b45c757deadfa81574e352.zip binutils-0c18fee5b37f838c89b45c757deadfa81574e352.tar.gz binutils-0c18fee5b37f838c89b45c757deadfa81574e352.tar.bz2 |
merge from gcc
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 |