aboutsummaryrefslogtreecommitdiff
path: root/argp
diff options
context:
space:
mode:
authorGabriel F. T. Gomes <gabriel@inconstante.eti.br>2018-06-06 11:48:49 -0300
committerGabriel F. T. Gomes <gabriel@inconstante.eti.br>2019-02-21 10:28:50 -0300
commitf43b8dd55588c32d12a461251e4f7598c5fed97f (patch)
treef4d0ba0396fc8740476256e709075302d7e60d4e /argp
parentdc0afac3252d0c53716ccaf0b424f7769a66d695 (diff)
downloadglibc-f43b8dd55588c32d12a461251e4f7598c5fed97f.tar
glibc-f43b8dd55588c32d12a461251e4f7598c5fed97f.tar.gz
glibc-f43b8dd55588c32d12a461251e4f7598c5fed97f.tar.bz2
glibc-f43b8dd55588c32d12a461251e4f7598c5fed97f.zip
Add internal implementations for argp.h, err.h, and error.h functions
Since the introduction of explicit flags in the internal implementation of the printf family of functions, the 'mode' parameter can be used to select which format long double parameters have (with the mode flag: PRINTF_LDBL_IS_DBL). This patch uses this feature in the implementation of some functions in argp.h, err.h, and error.h (only those that take a format string and positional parameters). Future patches will add support for 'nldbl' and 'ieee128' versions of these functions. Tested for powerpc64le and x86_64.
Diffstat (limited to 'argp')
-rw-r--r--argp/argp-help.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/argp/argp-help.c b/argp/argp-help.c
index 52ec2316fa..3b1727c4aa 100644
--- a/argp/argp-help.c
+++ b/argp/argp-help.c
@@ -1750,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))
{
@@ -1758,18 +1759,14 @@ __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 _LIBC
char *buf;
- if (__vasprintf_internal (&buf, fmt, ap, 0) < 0)
+ if (__vasprintf_internal (&buf, fmt, ap, mode_flags) < 0)
buf = NULL;
__fxprintf (stream, "%s: %s\n",
@@ -1789,14 +1786,20 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
__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
@@ -1810,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))
{
@@ -1833,13 +1837,10 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
if (fmt)
{
- va_list ap;
-
- va_start (ap, fmt);
#ifdef _LIBC
char *buf;
- if (__vasprintf_internal (&buf, fmt, ap, 0) < 0)
+ if (__vasprintf_internal (&buf, fmt, ap, mode_flags) < 0)
buf = NULL;
__fxprintf (stream, ": %s", buf);
@@ -1851,8 +1852,6 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
vfprintf (stream, fmt, ap);
#endif
-
- va_end (ap);
}
if (errnum)
@@ -1889,6 +1888,15 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
}
}
}
+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