- if (stdoutput == NULL)
- {
- as_perror (_("FATAL: Can't create %s"), name);
- exit (EXIT_FAILURE);
- }
-}
-
-void
-output_file_close (filename)
- char *filename;
-{
- if (EOF == fclose (stdoutput))
- {
- as_perror (_("FATAL: Can't close %s"), filename);
- exit (EXIT_FAILURE);
- }
- stdoutput = NULL; /* Trust nobody! */
-}
-
-void
-output_file_append (where, length, filename)
- char *where;
- long length;
- char *filename;
-{
- for (; length; length--, where++)
- {
- (void) putc (*where, stdoutput);
- if (ferror (stdoutput))
- /* if ( EOF == (putc( *where, stdoutput )) ) */
- {
- as_perror (_("Failed to emit an object byte"), filename);
- as_fatal (_("Can't continue"));
- }
- }
+ /* Close the bfd. */
+ if (had_errors ())
+ res = bfd_cache_close_all ();
+ else
+ res = bfd_close (stdoutput);
+
+ /* Prevent an infinite loop - if the close failed we will call as_fatal
+ which will call xexit() which may call this function again... */
+ stdoutput = NULL;
+
+ if (! res)
+ as_fatal (_("can't close %s: %s"), filename,
+ bfd_errmsg (bfd_get_error ()));