Back to index

cell-binutils  2.17cvs20070401
output-file.c
Go to the documentation of this file.
00001 /* output-file.c -  Deal with the output file
00002    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001,
00003    2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00004 
00005    This file is part of GAS, the GNU Assembler.
00006 
00007    GAS is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    GAS is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with GAS; see the file COPYING.  If not, write to
00019    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00020    02110-1301, USA.  */
00021 
00022 #include "as.h"
00023 #include "output-file.h"
00024 
00025 #ifndef TARGET_MACH
00026 #define TARGET_MACH 0
00027 #endif
00028 
00029 bfd *stdoutput;
00030 
00031 void
00032 output_file_create (char *name)
00033 {
00034   if (name[0] == '-' && name[1] == '\0')
00035     as_fatal (_("can't open a bfd on stdout %s"), name);
00036 
00037   else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
00038     {
00039       bfd_error_type err = bfd_get_error ();
00040 
00041       if (err == bfd_error_invalid_target)
00042        as_fatal (_("selected target format '%s' unknown"), TARGET_FORMAT);
00043       else
00044        as_fatal (_("can't create %s: %s"), name, bfd_errmsg (err));
00045     }
00046 
00047   bfd_set_format (stdoutput, bfd_object);
00048   bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH);
00049   if (flag_traditional_format)
00050     stdoutput->flags |= BFD_TRADITIONAL_FORMAT;
00051 }
00052 
00053 void
00054 output_file_close (char *filename)
00055 {
00056   bfd_boolean res;
00057 
00058   if (stdoutput == NULL)
00059     return;
00060     
00061   /* Close the bfd.  */
00062   res = bfd_close (stdoutput);
00063 
00064   /* Prevent an infinite loop - if the close failed we will call as_fatal
00065      which will call xexit() which may call this function again...  */
00066   stdoutput = NULL;
00067 
00068   if (! res)
00069     as_fatal (_("can't close %s: %s"), filename,
00070              bfd_errmsg (bfd_get_error ()));
00071 }