133965Sjdp/* output-file.c - Deal with the output file 2218822Sdim Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001, 3218822Sdim 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 433965Sjdp 533965Sjdp This file is part of GAS, the GNU Assembler. 633965Sjdp 733965Sjdp GAS is free software; you can redistribute it and/or modify 833965Sjdp it under the terms of the GNU General Public License as published by 933965Sjdp the Free Software Foundation; either version 2, or (at your option) 1033965Sjdp any later version. 1133965Sjdp 1233965Sjdp GAS is distributed in the hope that it will be useful, 1333965Sjdp but WITHOUT ANY WARRANTY; without even the implied warranty of 1433965Sjdp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1533965Sjdp GNU General Public License for more details. 1633965Sjdp 1733965Sjdp You should have received a copy of the GNU General Public License 1833965Sjdp along with GAS; see the file COPYING. If not, write to 19218822Sdim the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 20218822Sdim 02110-1301, USA. */ 2133965Sjdp 2233965Sjdp#include "as.h" 2333965Sjdp#include "output-file.h" 2433965Sjdp 2533965Sjdp#ifndef TARGET_MACH 2633965Sjdp#define TARGET_MACH 0 2733965Sjdp#endif 2833965Sjdp 2933965Sjdpbfd *stdoutput; 3033965Sjdp 3133965Sjdpvoid 32130561Sobrienoutput_file_create (char *name) 3333965Sjdp{ 3433965Sjdp if (name[0] == '-' && name[1] == '\0') 3589857Sobrien as_fatal (_("can't open a bfd on stdout %s"), name); 3689857Sobrien 3733965Sjdp else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT))) 3833965Sjdp { 39218822Sdim bfd_error_type err = bfd_get_error (); 40218822Sdim 41218822Sdim if (err == bfd_error_invalid_target) 42218822Sdim as_fatal (_("selected target format '%s' unknown"), TARGET_FORMAT); 43218822Sdim else 44218822Sdim as_fatal (_("can't create %s: %s"), name, bfd_errmsg (err)); 4533965Sjdp } 4689857Sobrien 4733965Sjdp bfd_set_format (stdoutput, bfd_object); 4833965Sjdp bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH); 4938889Sjdp if (flag_traditional_format) 5038889Sjdp stdoutput->flags |= BFD_TRADITIONAL_FORMAT; 5133965Sjdp} 5233965Sjdp 5333965Sjdpvoid 54130561Sobrienoutput_file_close (char *filename) 5533965Sjdp{ 56218822Sdim bfd_boolean res; 5733965Sjdp 5833965Sjdp if (stdoutput == NULL) 59218822Sdim return; 60218822Sdim 61218822Sdim /* Close the bfd. */ 62218822Sdim res = bfd_close (stdoutput); 6333965Sjdp 64218822Sdim /* Prevent an infinite loop - if the close failed we will call as_fatal 65218822Sdim which will call xexit() which may call this function again... */ 6689857Sobrien stdoutput = NULL; 6733965Sjdp 68218822Sdim if (! res) 69218822Sdim as_fatal (_("can't close %s: %s"), filename, 70218822Sdim bfd_errmsg (bfd_get_error ())); 7133965Sjdp} 72