]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - argp/argp-help.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / argp / argp-help.c
index de709dff8f2f4cfbd22ccb56775f5aafb79b2424..85f5792bfeef91b96453630a40e4fb9ee3d943a8 100644 (file)
@@ -1,5 +1,5 @@
 /* Hierarchial argument parsing help output
-   Copyright (C) 1995-2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -14,9 +14,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #ifndef _GNU_SOURCE
 # define _GNU_SOURCE   1
 #include <config.h>
 #endif
 
-#ifndef alloca
-# ifdef __GNUC__
-#  define alloca __builtin_alloca
-#  define HAVE_ALLOCA 1
+/* AIX requires this to be the first thing in the file.  */
+#ifndef __GNUC__
+# if HAVE_ALLOCA_H || defined _LIBC
+#  include <alloca.h>
 # else
-#  if defined HAVE_ALLOCA_H || defined _LIBC
-#   include <alloca.h>
+#  ifdef _AIX
+#pragma alloca
 #  else
-#   ifdef _AIX
- #pragma alloca
-#   else
-#    ifndef alloca
+#   ifndef alloca /* predefined by HP cc +Olibcalls */
 char *alloca ();
-#    endif
 #   endif
 #  endif
 # endif
 #endif
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <stdarg.h>
-#include <malloc.h>
 #include <ctype.h>
-#ifdef USE_IN_LIBIO
+#include <limits.h>
+#ifdef _LIBC
+# include <../libio/libioP.h>
 # include <wchar.h>
 #endif
 
@@ -62,16 +59,33 @@ char *alloca ();
 #  include <libintl.h>
 #  ifdef _LIBC
 #   undef dgettext
-#   define dgettext(domain, msgid) __dcgettext (domain, msgid, LC_MESSAGES)
+#   define dgettext(domain, msgid) \
+  __dcgettext (domain, msgid, LC_MESSAGES)
 #  endif
 # else
 #  define dgettext(domain, msgid) (msgid)
 # endif
 #endif
 
-#include "argp.h"
-#include "argp-fmtstream.h"
+#ifndef _LIBC
+# if HAVE_STRERROR_R
+#  if !HAVE_DECL_STRERROR_R
+char *strerror_r (int errnum, char *buf, size_t buflen);
+#  endif
+# else
+#  if !HAVE_DECL_STRERROR
+char *strerror (int errnum);
+#  endif
+# endif
+#endif
+
+#include <argp.h>
+#include <argp-fmtstream.h>
 #include "argp-namefrob.h"
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
 \f
 /* User-selectable (using an environment variable) formatting parameters.
 
@@ -114,42 +128,39 @@ struct uparams
   int header_col;
   int usage_indent;
   int rmargin;
-
-  int valid;                   /* True when the values in here are valid.  */
 };
 
 /* This is a global variable, as user options are only ever read once.  */
 static struct uparams uparams = {
   DUP_ARGS, DUP_ARGS_NOTE,
   SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
-  USAGE_INDENT, RMARGIN,
-  0
+  USAGE_INDENT, RMARGIN
 };
 
 /* A particular uparam, and what the user name is.  */
 struct uparam_name
 {
-  const char *name;            /* User name.  */
-  int is_bool;                 /* Whether it's `boolean'.  */
-  size_t uparams_offs;         /* Location of the (int) field in UPARAMS.  */
+  const char name[14];         /* User name.  */
+  bool is_bool;                        /* Whether it's `boolean'.  */
+  uint8_t uparams_offs;                /* Location of the (int) field in UPARAMS.  */
 };
 
 /* The name-field mappings we know about.  */
 static const struct uparam_name uparam_names[] =
 {
-  { "dup-args",       1, offsetof (struct uparams, dup_args) },
-  { "dup-args-note",  1, offsetof (struct uparams, dup_args_note) },
-  { "short-opt-col",  0, offsetof (struct uparams, short_opt_col) },
-  { "long-opt-col",   0, offsetof (struct uparams, long_opt_col) },
-  { "doc-opt-col",    0, offsetof (struct uparams, doc_opt_col) },
-  { "opt-doc-col",    0, offsetof (struct uparams, opt_doc_col) },
-  { "header-col",     0, offsetof (struct uparams, header_col) },
-  { "usage-indent",   0, offsetof (struct uparams, usage_indent) },
-  { "rmargin",        0, offsetof (struct uparams, rmargin) },
-  { 0 }
+  { "dup-args",       true, offsetof (struct uparams, dup_args) },
+  { "dup-args-note",  true, offsetof (struct uparams, dup_args_note) },
+  { "short-opt-col",  false, offsetof (struct uparams, short_opt_col) },
+  { "long-opt-col",   false, offsetof (struct uparams, long_opt_col) },
+  { "doc-opt-col",    false, offsetof (struct uparams, doc_opt_col) },
+  { "opt-doc-col",    false, offsetof (struct uparams, opt_doc_col) },
+  { "header-col",     false, offsetof (struct uparams, header_col) },
+  { "usage-indent",   false, offsetof (struct uparams, usage_indent) },
+  { "rmargin",        false, offsetof (struct uparams, rmargin) }
 };
+#define nuparam_names (sizeof (uparam_names) / sizeof (uparam_names[0]))
 
-/* Read user options from the environment, and fill in UPARAMS appropiately.  */
+/* Read user options from the environment, and fill in UPARAMS appropriately.  */
 static void
 fill_in_uparams (const struct argp_state *state)
 {
@@ -203,22 +214,27 @@ fill_in_uparams (const struct argp_state *state)
                SKIPWS (arg);
              }
 
-           for (un = uparam_names; un->name; un++)
+           un = uparam_names;
+           size_t u;
+           for (u = 0; u < nuparam_names; ++un, ++u)
              if (strlen (un->name) == var_len
                  && strncmp (var, un->name, var_len) == 0)
                {
                  if (unspec && !un->is_bool)
                    __argp_failure (state, 0, 0,
-                                   dgettext (state->root_argp->argp_domain, "\
+                                   dgettext (state == NULL ? NULL
+                                             : state->root_argp->argp_domain,
+                                             "\
 %.*s: ARGP_HELP_FMT parameter requires a value"),
                                    (int) var_len, var);
                  else
                    *(int *)((char *)&uparams + un->uparams_offs) = val;
                  break;
                }
-           if (! un->name)
+           if (u == nuparam_names)
              __argp_failure (state, 0, 0,
-                             dgettext (state->root_argp->argp_domain, "\
+                             dgettext (state == NULL ? NULL
+                                       : state->root_argp->argp_domain, "\
 %.*s: Unknown ARGP_HELP_FMT parameter"),
                              (int) var_len, var);
 
@@ -229,7 +245,8 @@ fill_in_uparams (const struct argp_state *state)
        else if (*var)
          {
            __argp_failure (state, 0, 0,
-                           dgettext (state->root_argp->argp_domain,
+                           dgettext (state == NULL ? NULL
+                                     : state->root_argp->argp_domain,
                                      "Garbage in ARGP_HELP_FMT: %s"), var);
            break;
          }
@@ -258,11 +275,11 @@ fill_in_uparams (const struct argp_state *state)
      -xARG, -yARG, --long1=ARG, --long2=ARG        Documentation...
 
    Where ARG will be omitted if there's no argument, for this option, or
-   will be surrounded by "[" and "]" appropiately if the argument is
-   optional.  The documentation string is word-wrapped appropiately, and if
+   will be surrounded by "[" and "]" appropriately if the argument is
+   optional.  The documentation string is word-wrapped appropriately, and if
    the list of options is long enough, it will be started on a separate line.
    If there are no short options for a given option, the first long option is
-   indented slighly in a way that's supposed to make most long options appear
+   indented slightly in a way that's supposed to make most long options appear
    to be in a separate column.
 
    For example, the following output (from ps):
@@ -294,13 +311,13 @@ fill_in_uparams (const struct argp_state *state)
      {"no-parent", 'P',              0,     0, "Include processes without parents"},
      {0,           'x',       0,     OPTION_ALIAS},
      {"all-fields",'Q',       0,     0, "Don't elide unusable fields (normally"
-                                        " if there's some reason ps can't"
+                                       " if there's some reason ps can't"
                                        " print a field for any process, it's"
-                                        " removed from the output entirely)" },
+                                       " removed from the output entirely)" },
      {"reverse",   'r',       0,     0, "Reverse the order of any sort"},
      {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
      {"session",   OPT_SESS,  "SID", OPTION_ARG_OPTIONAL,
-                                        "Add the processes from the session"
+                                       "Add the processes from the session"
                                        " SID (which defaults to the sid of"
                                        " the current process)" },
 
@@ -340,7 +357,7 @@ struct hol_entry
   /* A pointers into the HOL's short_options field, to the first short option
      letter for this entry.  The order of the characters following this point
      corresponds to the order of options pointed to by OPT, and there are at
-     most NUM.  A short option recorded in a option following OPT is only
+     most NUM.  A short option recorded in an option following OPT is only
      valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
      probably been shadowed by some other entry).  */
   char *short_options;
@@ -441,6 +458,9 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster)
       hol->short_options = malloc (num_short_options + 1);
 
       assert (hol->entries && hol->short_options);
+#if SIZE_MAX <= UINT_MAX
+      assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
+#endif
 
       /* Fill in the entries.  */
       so = hol->short_options;
@@ -520,7 +540,7 @@ hol_free (struct hol *hol)
   free (hol);
 }
 \f
-static inline int
+static int
 hol_entry_short_iterate (const struct hol_entry *entry,
                         int (*func)(const struct argp_option *opt,
                                     const struct argp_option *real,
@@ -546,6 +566,7 @@ hol_entry_short_iterate (const struct hol_entry *entry,
 }
 
 static inline int
+__attribute__ ((always_inline))
 hol_entry_long_iterate (const struct hol_entry *entry,
                        int (*func)(const struct argp_option *opt,
                                    const struct argp_option *real,
@@ -651,9 +672,9 @@ hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
 {
   /* If one cluster is deeper than the other, use its ancestor at the same
      level, so that finding the common ancestor is straightforward.  */
-  while (cl1->depth < cl2->depth)
+  while (cl1->depth > cl2->depth)
     cl1 = cl1->parent;
-  while (cl2->depth < cl1->depth)
+  while (cl2->depth > cl1->depth)
     cl2 = cl2->parent;
 
   /* Now reduce both clusters to their ancestors at the point where both have
@@ -715,12 +736,12 @@ hol_entry_cmp (const struct hol_entry *entry1,
   if (entry1->cluster != entry2->cluster)
     {
       /* The entries are not within the same cluster, so we can't compare them
-        directly, we have to use the appropiate clustering level too.  */
+        directly, we have to use the appropriate clustering level too.  */
       if (! entry1->cluster)
        /* ENTRY1 is at the `base level', not in a cluster, so we have to
           compare it's group number with that of the base cluster in which
           ENTRY2 resides.  Note that if they're in the same group, the
-          clustered option always comes laster.  */
+          clustered option always comes last.  */
        return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
       else if (! entry2->cluster)
        /* Likewise, but ENTRY2's not in a cluster.  */
@@ -741,9 +762,9 @@ hol_entry_cmp (const struct hol_entry *entry1,
       const char *long2 = hol_entry_first_long (entry2);
 
       if (doc1)
-       doc1 = canon_doc_option (&long1);
+       doc1 = long1 != NULL && canon_doc_option (&long1);
       if (doc2)
-       doc2 = canon_doc_option (&long2);
+       doc2 = long2 != NULL && canon_doc_option (&long2);
 
       if (doc1 != doc2)
        /* `documentation' options always follow normal options (or
@@ -832,6 +853,11 @@ hol_append (struct hol *hol, struct hol *more)
          char *short_options =
            malloc (hol_so_len + strlen (more->short_options) + 1);
 
+         assert (entries && short_options);
+#if SIZE_MAX <= UINT_MAX
+         assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry));
+#endif
+
          __mempcpy (__mempcpy (entries, hol->entries,
                                hol->num_entries * sizeof (struct hol_entry)),
                     more->entries,
@@ -961,7 +987,7 @@ static const char *
 filter_doc (const char *doc, int key, const struct argp *argp,
            const struct argp_state *state)
 {
-  if (argp->help_filter)
+  if (argp && argp->help_filter)
     /* We must apply a user filter to this output.  */
     {
       void *input = __argp_input (argp, state);
@@ -972,7 +998,7 @@ filter_doc (const char *doc, int key, const struct argp *argp,
     return doc;
 }
 
-/* Prints STR as a header line, with the margin lines set appropiately, and
+/* Prints STR as a header line, with the margin lines set appropriately, and
    notes the fact that groups should be separated with a blank line.  ARGP is
    the argp that should dictate any user doc filtering to take place.  Note
    that the previous wrap margin isn't restored, but the left margin is reset
@@ -1079,7 +1105,9 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
            __argp_fmtstream_putc (stream, '-');
            __argp_fmtstream_putc (stream, *so);
            if (!have_long_opt || uparams.dup_args)
-             arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream);
+             arg (real, " %s", "[%s]",
+                  state == NULL ? NULL : state->root_argp->argp_domain,
+                  stream);
            else if (real->arg)
              hhstate->suppressed_dup_arg = 1;
          }
@@ -1099,26 +1127,22 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
               have been done on the original; but documentation options
               should be pretty rare anyway...  */
            __argp_fmtstream_puts (stream,
-                                  dgettext (state->root_argp->argp_domain,
+                                  dgettext (state == NULL ? NULL
+                                            : state->root_argp->argp_domain,
                                             opt->name));
          }
     }
   else
     /* A real long option.  */
     {
-      int first_long_opt = 1;
-
       __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
       for (opt = real, num = entry->num; num > 0; opt++, num--)
        if (opt->name && ovisible (opt))
          {
            comma (uparams.long_opt_col, &pest);
            __argp_fmtstream_printf (stream, "--%s", opt->name);
-           if (first_long_opt || uparams.dup_args)
-             arg (real, "=%s", "[=%s]", state->root_argp->argp_domain,
-                  stream);
-           else if (real->arg)
-             hhstate->suppressed_dup_arg = 1;
+           arg (real, "=%s", "[=%s]",
+                state == NULL ? NULL : state->root_argp->argp_domain, stream);
          }
     }
 
@@ -1137,7 +1161,8 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
     }
   else
     {
-      const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain,
+      const char *tstr = real->doc ? dgettext (state == NULL ? NULL
+                                              : state->root_argp->argp_domain,
                                               real->doc) : 0;
       const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
       if (fstr && *fstr)
@@ -1185,7 +1210,8 @@ hol_help (struct hol *hol, const struct argp_state *state,
 
   if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
     {
-      const char *tstr = dgettext (state->root_argp->argp_domain, "\
+      const char *tstr = dgettext (state == NULL ? NULL
+                                  : state->root_argp->argp_domain, "\
 Mandatory or optional arguments to long options are also mandatory or \
 optional for any corresponding short options.");
       const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
@@ -1514,7 +1540,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
 }
 \f
 /* Output a usage message for ARGP to STREAM.  If called from
-   argp_state_help, STATE is the relevent parsing state.  FLAGS are from the
+   argp_state_help, STATE is the relevant parsing state.  FLAGS are from the
    set ARGP_HELP_*.  NAME is what to use wherever a `program name' is
    needed. */
 static void
@@ -1528,15 +1554,18 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
   if (! stream)
     return;
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
   __flockfile (stream);
+#endif
 
-  if (! uparams.valid)
-    fill_in_uparams (state);
+  fill_in_uparams (state);
 
   fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
   if (! fs)
     {
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
       __funlockfile (stream);
+#endif
       return;
     }
 
@@ -1644,7 +1673,9 @@ Try `%s --help' or `%s --usage' for more information.\n"),
       anything = 1;
     }
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
   __funlockfile (stream);
+#endif
 
   if (hol)
     hol_free (hol);
@@ -1663,6 +1694,32 @@ void __argp_help (const struct argp *argp, FILE *stream,
 weak_alias (__argp_help, argp_help)
 #endif
 
+#ifndef _LIBC
+char *__argp_basename (char *name)
+{
+  char *short_name = strrchr (name, '/');
+  return short_name ? short_name + 1 : name;
+}
+
+char *
+__argp_short_program_name (void)
+{
+# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+  return program_invocation_short_name;
+# elif HAVE_DECL_PROGRAM_INVOCATION_NAME
+  return __argp_basename (program_invocation_name);
+# else
+  /* FIXME: What now? Miles suggests that it is better to use NULL,
+     but currently the value is passed on directly to fputs_unlocked,
+     so that requires more changes. */
+# if __GNUC__
+#  warning No reasonable value to return
+# endif /* __GNUC__ */
+  return "";
+# endif
+}
+#endif
+
 /* Output, if appropriate, a usage message for STATE to STREAM.  FLAGS are
    from the set ARGP_HELP_*.  */
 void
@@ -1674,7 +1731,7 @@ __argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
        flags |= ARGP_HELP_LONG_ONLY;
 
       _help (state ? state->root_argp : 0, state, stream, flags,
-            state ? state->name : program_invocation_short_name);
+            state ? state->name : __argp_short_program_name ());
 
       if (!state || ! (state->flags & ARGP_NO_EXIT))
        {
@@ -1693,7 +1750,8 @@ weak_alias (__argp_state_help, argp_state_help)
    by the program name and `:', to stderr, and followed by a `Try ... --help'
    message, then exit (1).  */
 void
-__argp_error (const struct argp_state *state, const char *fmt, ...)
+__argp_error_internal (const struct argp_state *state, const char *fmt,
+                      va_list ap, unsigned int mode_flags)
 {
   if (!state || !(state->flags & ARGP_NO_ERRS))
     {
@@ -1701,47 +1759,47 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 
       if (stream)
        {
-         va_list ap;
-
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __flockfile (stream);
+#endif
 
-         va_start (ap, fmt);
-
-#ifdef USE_IN_LIBIO
-         if (_IO_fwide (stream, 0) > 0)
-           {
-             char *buf;
+#ifdef _LIBC
+         char *buf;
 
-             asprintf (&buf, fmt, ap);
+         if (__vasprintf_internal (&buf, fmt, ap, mode_flags) < 0)
+           buf = NULL;
 
-             fwprintf (stream, L"%s: %s\n",
-                       state ? state->name : program_invocation_short_name,
-                       buf);
+         __fxprintf (stream, "%s: %s\n",
+                     state ? state->name : __argp_short_program_name (), buf);
 
-             free (buf);
-           }
-         else
-#endif
-           {
-             fputs_unlocked (state
-                             ? state->name : program_invocation_short_name,
-                             stream);
-             putc_unlocked (':', stream);
-             putc_unlocked (' ', stream);
+         free (buf);
+#else
+         fputs_unlocked (state ? state->name : __argp_short_program_name (),
+                         stream);
+         putc_unlocked (':', stream);
+         putc_unlocked (' ', stream);
 
-             vfprintf (stream, fmt, ap);
+         vfprintf (stream, fmt, ap);
 
-             putc_unlocked ('\n', stream);
-           }
+         putc_unlocked ('\n', stream);
+#endif
 
          __argp_state_help (state, stream, ARGP_HELP_STD_ERR);
 
-         va_end (ap);
-
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __funlockfile (stream);
+#endif
        }
     }
 }
+void
+__argp_error (const struct argp_state *state, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  __argp_error_internal (state, fmt, ap, 0);
+  va_end (ap);
+}
 #ifdef weak_alias
 weak_alias (__argp_error, argp_error)
 #endif
@@ -1755,8 +1813,9 @@ weak_alias (__argp_error, argp_error)
    *parsing errors*, and the former is for other problems that occur during
    parsing but don't reflect a (syntactic) problem with the input.  */
 void
-__argp_failure (const struct argp_state *state, int status, int errnum,
-               const char *fmt, ...)
+__argp_failure_internal (const struct argp_state *state, int status,
+                        int errnum, const char *fmt, va_list ap,
+                        unsigned int mode_flags)
 {
   if (!state || !(state->flags & ARGP_NO_ERRS))
     {
@@ -1764,78 +1823,80 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 
       if (stream)
        {
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __flockfile (stream);
+#endif
 
-#ifdef USE_IN_LIBIO
-         if (_IO_fwide (stream, 0) > 0)
-           fputws_unlocked (state
-                            ? state->name : program_invocation_short_name,
-                            stream);
-         else
+#ifdef _LIBC
+         __fxprintf (stream, "%s",
+                     state ? state->name : __argp_short_program_name ());
+#else
+         fputs_unlocked (state ? state->name : __argp_short_program_name (),
+                         stream);
 #endif
-           fputs_unlocked (state
-                           ? state->name : program_invocation_short_name,
-                           stream);
 
          if (fmt)
            {
-             va_list ap;
+#ifdef _LIBC
+             char *buf;
 
-             va_start (ap, fmt);
-#ifdef USE_IN_LIBIO
-             if (_IO_fwide (stream, 0) > 0)
-               {
-                 char *buf;
+             if (__vasprintf_internal (&buf, fmt, ap, mode_flags) < 0)
+               buf = NULL;
 
-                 asprintf (&buf, fmt, ap);
+             __fxprintf (stream, ": %s", buf);
 
-                 fwprintf (stream, L": %s", buf);
+             free (buf);
+#else
+             putc_unlocked (':', stream);
+             putc_unlocked (' ', stream);
 
-                 free (buf);
-               }
-             else
+             vfprintf (stream, fmt, ap);
 #endif
-               {
-                 putc_unlocked (':', stream);
-                 putc_unlocked (' ', stream);
-
-                 vfprintf (stream, fmt, ap);
-               }
-
-             va_end (ap);
            }
 
          if (errnum)
            {
              char buf[200];
 
-#ifdef USE_IN_LIBIO
-             if (_IO_fwide (stream, 0) > 0)
-               fwprintf (stream, ": %s",
+#ifdef _LIBC
+             __fxprintf (stream, ": %s",
                          __strerror_r (errnum, buf, sizeof (buf)));
-             else
+#else
+             putc_unlocked (':', stream);
+             putc_unlocked (' ', stream);
+# ifdef HAVE_STRERROR_R
+             fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
+# else
+             fputs (strerror (errnum), stream);
+# endif
 #endif
-               {
-                 putc_unlocked (':', stream);
-                 putc_unlocked (' ', stream);
-                 fputs (__strerror_r (errnum, buf, sizeof (buf)), stream);
-               }
            }
 
-#ifdef USE_IN_LIBIO
+#ifdef _LIBC
          if (_IO_fwide (stream, 0) > 0)
            putwc_unlocked (L'\n', stream);
          else
 #endif
            putc_unlocked ('\n', stream);
 
+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
          __funlockfile (stream);
+#endif
 
          if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
            exit (status);
        }
     }
 }
+void
+__argp_failure (const struct argp_state *state, int status, int errnum,
+               const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  __argp_failure_internal (state, status, errnum, fmt, ap, 0);
+  va_end (ap);
+}
 #ifdef weak_alias
 weak_alias (__argp_failure, argp_failure)
 #endif