X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=libiberty%2Fargv.c;h=a04f50d7f4910a02666a81d71317a6f4692dfca3;hb=2091ff6689ae73c4b95338a435d1c6e7b743599e;hp=e76c1f825d26cb1c2f111f1585222cb6bafaa6bd;hpb=decc7c8a1cd784b2edeff50ee0f30572237b71f6;p=thirdparty%2Fgcc.git diff --git a/libiberty/argv.c b/libiberty/argv.c index e76c1f825d26..a04f50d7f491 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