From f43b8dd55588c32d12a461251e4f7598c5fed97f Mon Sep 17 00:00:00 2001 From: "Gabriel F. T. Gomes" Date: Wed, 6 Jun 2018 11:48:49 -0300 Subject: 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. --- misc/err.c | 23 ++++++++++++++++++----- misc/error.c | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 20 deletions(-) (limited to 'misc') diff --git a/misc/err.c b/misc/err.c index 7c8f539..988ec8f 100644 --- a/misc/err.c +++ b/misc/err.c @@ -38,19 +38,20 @@ extern char *__progname; } void -vwarnx (const char *format, __gnuc_va_list ap) +__vwarnx_internal (const char *format, __gnuc_va_list ap, + unsigned int mode_flags) { flockfile (stderr); __fxprintf (stderr, "%s: ", __progname); if (format != NULL) - __vfxprintf (stderr, format, ap); + __vfxprintf (stderr, format, ap, mode_flags); __fxprintf (stderr, "\n"); funlockfile (stderr); } -libc_hidden_def (vwarnx) void -vwarn (const char *format, __gnuc_va_list ap) +__vwarn_internal (const char *format, __gnuc_va_list ap, + unsigned int mode_flags) { int error = errno; @@ -58,7 +59,7 @@ vwarn (const char *format, __gnuc_va_list ap) if (format != NULL) { __fxprintf (stderr, "%s: ", __progname); - __vfxprintf (stderr, format, ap); + __vfxprintf (stderr, format, ap, mode_flags); __set_errno (error); __fxprintf (stderr, ": %m\n"); } @@ -69,8 +70,20 @@ vwarn (const char *format, __gnuc_va_list ap) } funlockfile (stderr); } + +void +vwarn (const char *format, __gnuc_va_list ap) +{ + __vwarn_internal (format, ap, 0); +} libc_hidden_def (vwarn) +void +vwarnx (const char *format, __gnuc_va_list ap) +{ + __vwarnx_internal (format, ap, 0); +} +libc_hidden_def (vwarnx) void warn (const char *format, ...) diff --git a/misc/error.c b/misc/error.c index 556261d..e090d1b 100644 --- a/misc/error.c +++ b/misc/error.c @@ -200,10 +200,11 @@ print_errno_message (int errnum) } static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3)) -error_tail (int status, int errnum, const char *message, va_list args) +error_tail (int status, int errnum, const char *message, va_list args, + unsigned int mode_flags) { #if _LIBC - int ret = __vfxprintf (stderr, message, args); + int ret = __vfxprintf (stderr, message, args, mode_flags); if (ret < 0 && errno == ENOMEM && _IO_fwide (stderr, 0) > 0) /* Leave a trace in case the heap allocation of the message string failed. */ @@ -232,10 +233,9 @@ error_tail (int status, int errnum, const char *message, va_list args) If ERRNUM is nonzero, print its corresponding system error message. Exit with status STATUS if it is nonzero. */ void -error (int status, int errnum, const char *message, ...) +__error_internal (int status, int errnum, const char *message, + va_list args, unsigned int mode_flags) { - va_list args; - #if defined _LIBC && defined __libc_ptf_call /* We do not want this call to be cut short by a thread cancellation. Therefore disable cancellation for now. */ @@ -259,9 +259,7 @@ error (int status, int errnum, const char *message, ...) #endif } - va_start (args, message); - error_tail (status, errnum, message, args); - va_end (args); + error_tail (status, errnum, message, args, mode_flags); #ifdef _LIBC _IO_funlockfile (stderr); @@ -270,17 +268,25 @@ error (int status, int errnum, const char *message, ...) # endif #endif } + +void +error (int status, int errnum, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + __error_internal (status, errnum, message, ap, 0); + va_end (ap); +} /* Sometimes we want to have at most one error per line. This variable controls whether this mode is selected or not. */ int error_one_per_line; void -error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, ...) +__error_at_line_internal (int status, int errnum, const char *file_name, + unsigned int line_number, const char *message, + va_list args, unsigned int mode_flags) { - va_list args; - if (error_one_per_line) { static const char *old_file_name; @@ -331,9 +337,7 @@ error_at_line (int status, int errnum, const char *file_name, file_name, line_number); #endif - va_start (args, message); - error_tail (status, errnum, message, args); - va_end (args); + error_tail (status, errnum, message, args, mode_flags); #ifdef _LIBC _IO_funlockfile (stderr); @@ -343,6 +347,17 @@ error_at_line (int status, int errnum, const char *file_name, #endif } +void +error_at_line (int status, int errnum, const char *file_name, + unsigned int line_number, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + __error_at_line_internal (status, errnum, file_name, line_number, + message, ap, 0); + va_end (ap); +} + #ifdef _LIBC /* Make the weak alias. */ # undef error -- cgit v1.1