[binutils-gdb] Reinstate bfd_print_error as an extern function

Alan Modra amodra@sourceware.org
Sat Mar 9 10:32:17 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5cd52661808b9fdc2df56dd4c20a9a8ece72dbc1

commit 5cd52661808b9fdc2df56dd4c20a9a8ece72dbc1
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Mar 9 20:27:32 2024 +1030

    Reinstate bfd_print_error as an extern function
    
            * bfd.c (_bfd_print): Renamed from bfd_print_error.
            (bfd_print_error): Reinstate previous code but using the above.
            (error_handler_fprintf, error_handler_sprintf): Adjust.
            * bfd-in2.h: Regenerate.

Diff:
---
 bfd/bfd-in2.h |  3 +++
 bfd/bfd.c     | 33 +++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 76d450478a7..79b24a7f6e9 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2558,6 +2558,9 @@ void bfd_perror (const char *message);
 typedef void (*bfd_error_handler_type) (const char *, va_list);
 
 typedef int (*bfd_print_callback) (void *, const char *, ...);
+void bfd_print_error (bfd_print_callback print_func,
+    void *stream, const char *fmt, va_list ap);
+
 void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1;
 
 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
diff --git a/bfd/bfd.c b/bfd/bfd.c
index f40cf941edc..54061a34240 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1450,8 +1450,8 @@ _bfd_doprnt_scan (const char *format, va_list ap, union _bfd_doprnt_args *args)
 }
 
 static void
-bfd_print_error (bfd_print_callback print_func, void *stream,
-		 const char *fmt, va_list ap)
+_bfd_print (bfd_print_callback print_func, void *stream,
+	    const char *fmt, va_list ap)
 {
   union _bfd_doprnt_args args[MAX_ARGS];
 
@@ -1459,6 +1459,32 @@ bfd_print_error (bfd_print_callback print_func, void *stream,
   _bfd_doprnt (print_func, stream, fmt, args);
 }
 
+/*
+FUNCTION
+	bfd_print_error
+
+SYNOPSIS
+	void bfd_print_error (bfd_print_callback print_func,
+	  void *stream, const char *fmt, va_list ap);
+
+DESCRIPTION
+
+	This formats FMT and AP according to BFD "printf" rules,
+	sending the output to STREAM by repeated calls to PRINT_FUNC.
+	PRINT_FUNC is a printf-like function; it does not need to
+	implement the BFD printf format extensions.  This can be used
+	in a callback that is set via bfd_set_error_handler to turn
+	the error into ordinary output.
+*/
+
+void
+bfd_print_error (bfd_print_callback print_func, void *stream,
+		 const char *fmt, va_list ap)
+{
+  print_func (stream, "%s: ", _bfd_get_error_program_name ());
+  _bfd_print (print_func, stream, fmt, ap);
+}
+
 /* The standard error handler that prints to stderr.  */
 
 static void
@@ -1467,7 +1493,6 @@ error_handler_fprintf (const char *fmt, va_list ap)
   /* PR 4992: Don't interrupt output being sent to stdout.  */
   fflush (stdout);
 
-  fprintf (stderr, "%s: ", _bfd_get_error_program_name ());
   bfd_print_error ((bfd_print_callback) fprintf, stderr, fmt, ap);
 
   /* On AIX, putc is implemented as a macro that triggers a -Wunused-value
@@ -1526,7 +1551,7 @@ error_handler_sprintf (const char *fmt, va_list ap)
   error_stream.ptr = error_buf;
   error_stream.left = sizeof (error_buf);
 
-  bfd_print_error (err_sprintf, &error_stream, fmt, ap);
+  _bfd_print (err_sprintf, &error_stream, fmt, ap);
 
   size_t len = error_stream.ptr - error_buf;
   struct per_xvec_message **warn


More information about the Binutils-cvs mailing list