+/* Issue a non fatal error message. FILENAME, or if NULL then BFD,
+ are used to indicate the problematic file. SECTION, if non NULL,
+ is used to provide a section name. If FORMAT is non-null, then it
+ is used to print additional information via vfprintf. Finally the
+ bfd error message is printed. In summary, error messages are of
+ one of the following forms:
+
+ PROGRAM: file: bfd-error-message
+ PROGRAM: file[section]: bfd-error-message
+ PROGRAM: file: printf-message: bfd-error-message
+ PROGRAM: file[section]: printf-message: bfd-error-message. */
+
+void
+bfd_nonfatal_message (const char *filename,
+ const bfd *abfd,
+ const asection *section,
+ const char *format, ...)
+{
+ const char *errmsg;
+ const char *section_name;
+ va_list args;
+ enum bfd_error err = bfd_get_error ();
+
+ if (err == bfd_error_no_error)
+ errmsg = _("cause of error unknown");
+ else
+ errmsg = bfd_errmsg (err);
+ fflush (stdout);
+ section_name = NULL;
+ va_start (args, format);
+ fprintf (stderr, "%s", program_name);
+
+ if (abfd)
+ {
+ if (!filename)
+ filename = bfd_get_archive_filename (abfd);
+ if (section)
+ section_name = bfd_section_name (section);
+ }
+ if (section_name)
+ fprintf (stderr, ": %s[%s]", filename, section_name);
+ else
+ fprintf (stderr, ": %s", filename);
+
+ if (format)
+ {
+ fprintf (stderr, ": ");
+ vfprintf (stderr, format, args);
+ }
+ fprintf (stderr, ": %s\n", errmsg);
+ va_end (args);
+}
+