From 34eccf57b3d463638339dc56281db4e8fa023a69 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 17 Jun 1996 04:00:04 +0000 Subject: (argp_help, argp_state_help, argp_error, argp_failure): Handle null streams. --- libshouldbeinlibc/argp-help.c | 63 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/libshouldbeinlibc/argp-help.c b/libshouldbeinlibc/argp-help.c index df68d53e..96a020c8 100644 --- a/libshouldbeinlibc/argp-help.c +++ b/libshouldbeinlibc/argp-help.c @@ -734,6 +734,9 @@ void argp_help (const struct argp *argp, FILE *stream, int first = 1; struct hol *hol = 0; + if (! stream) + return; + stream = line_wrap_stream (stream, 0, RMARGIN, 0); assert (stream); @@ -806,7 +809,7 @@ void argp_help (const struct argp *argp, FILE *stream, void argp_state_help (struct argp_state *state, FILE *stream, unsigned flags) { - if (!state || ! (state->flags & ARGP_NO_ERRS)) + if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) { argp_help (state ? state->argp : 0, stream, flags, state ? state->name : program_invocation_name); @@ -827,22 +830,26 @@ argp_state_help (struct argp_state *state, FILE *stream, unsigned flags) void argp_error (struct argp_state *state, const char *fmt, ...) { - if (!state || ! (state->flags & ARGP_NO_ERRS)) + if (!state || !(state->flags & ARGP_NO_ERRS)) { - va_list ap; FILE *stream = state ? state->err_stream : stderr; - fputs (program_invocation_name, stream); - putc (':', stream); - putc (' ', stream); + if (stream) + { + va_list ap; - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); + fputs (program_invocation_name, stream); + putc (':', stream); + putc (' ', stream); - putc ('\n', stream); + va_start (ap, fmt); + vfprintf (stream, fmt, ap); + va_end (ap); + + putc ('\n', stream); - argp_state_help (state, stream, ARGP_HELP_STD_ERR); + argp_state_help (state, stream, ARGP_HELP_STD_ERR); + } } } @@ -860,27 +867,31 @@ argp_failure (struct argp_state *state, int status, int errnum, { if (!state || !(state->flags & ARGP_NO_ERRS)) { - va_list ap; FILE *stream = state ? state->err_stream : stderr; - fputs (state ? state->name : program_invocation_name, stream); - putc (':', stream); - putc (' ', stream); - - va_start (ap, fmt); - vfprintf (stream, fmt, ap); - va_end (ap); - - if (errnum) + if (stream) { + va_list ap; + + fputs (state ? state->name : program_invocation_name, stream); putc (':', stream); putc (' ', stream); - fputs (strerror (errnum), stream); - } - putc ('\n', stream); + va_start (ap, fmt); + vfprintf (stream, fmt, ap); + va_end (ap); - if (status) - exit (status); + if (errnum) + { + putc (':', stream); + putc (' ', stream); + fputs (strerror (errnum), stream); + } + + putc ('\n', stream); + + if (status) + exit (status); + } } } -- cgit v1.2.3