summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-06-17 04:00:04 +0000
committerMiles Bader <miles@gnu.org>1996-06-17 04:00:04 +0000
commit34eccf57b3d463638339dc56281db4e8fa023a69 (patch)
tree304f4c975f573481f6d49ea4f3bf144e1e4f3ee7
parent58f84a640d920b8d9377abdc114415611b1b7879 (diff)
(argp_help, argp_state_help, argp_error, argp_failure): Handle null streams.
-rw-r--r--libshouldbeinlibc/argp-help.c63
1 files 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);
+ }
}
}