1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

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.
This commit is contained in:
Gabriel F. T. Gomes
2018-06-06 11:48:49 -03:00
parent dc0afac325
commit f43b8dd555
6 changed files with 111 additions and 44 deletions

View File

@ -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