gdb/
[deliverable/binutils-gdb.git] / gas / output-file.c
index 446af306ca101d9611d947c1a274626235ab154a..e993033f4812ed967572a25c4ec36acac222afda 100644 (file)
@@ -1,12 +1,12 @@
 /* output-file.c -  Deal with the output file
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001,
 /* output-file.c -  Deal with the output file
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001,
-   2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This file is part of GAS, the GNU Assembler.
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
+   the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
    GAS is distributed in the hope that it will be useful,
    any later version.
 
    GAS is distributed in the hope that it will be useful,
@@ -36,11 +36,12 @@ output_file_create (char *name)
 
   else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
     {
 
   else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
     {
-      if (bfd_get_error () == bfd_error_invalid_target)
-       as_perror (_("Selected target format '%s' unknown"), TARGET_FORMAT);
+      bfd_error_type err = bfd_get_error ();
+
+      if (err == bfd_error_invalid_target)
+       as_fatal (_("selected target format '%s' unknown"), TARGET_FORMAT);
       else
       else
-       as_perror (_("FATAL: can't create %s"), name);
-      exit (EXIT_FAILURE);
+       as_fatal (_("can't create %s: %s"), name, bfd_errmsg (err));
     }
 
   bfd_set_format (stdoutput, bfd_object);
     }
 
   bfd_set_format (stdoutput, bfd_object);
@@ -52,12 +53,19 @@ output_file_create (char *name)
 void
 output_file_close (char *filename)
 {
 void
 output_file_close (char *filename)
 {
+  bfd_boolean res;
+
+  if (stdoutput == NULL)
+    return;
+    
   /* Close the bfd.  */
   /* Close the bfd.  */
-  if (bfd_close (stdoutput) == 0)
-    {
-      bfd_perror (filename);
-      as_perror (_("FATAL: can't close %s\n"), filename);
-      exit (EXIT_FAILURE);
-    }
-  stdoutput = NULL;            /* Trust nobody!  */
+  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 ()));
 }
 }
This page took 0.023471 seconds and 4 git commands to generate.