1 /* output-file.c - Deal with the output file
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "output-file.h"
44 output_file_create (char *name)
46 if (name[0] == '-' && name[1] == '\0')
47 as_fatal (_("can't open a bfd on stdout %s"), name);
49 else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
51 as_perror (_("FATAL: can't create %s"), name);
55 bfd_set_format (stdoutput, bfd_object);
57 bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH);
59 if (flag_traditional_format)
60 stdoutput->flags |= BFD_TRADITIONAL_FORMAT;
64 output_file_close (char *filename)
68 if (bfd_close (stdoutput) == 0)
70 bfd_perror (filename);
71 as_perror (_("FATAL: can't close %s\n"), filename);
75 /* Close the bfd without getting bfd to write out anything by itself. */
76 if (bfd_close_all_done (stdoutput) == 0)
78 as_perror (_("FATAL: can't close %s\n"), filename);
82 stdoutput = NULL; /* Trust nobody! */
87 output_file_append (where, length, filename)
88 char *where ATTRIBUTE_UNUSED;
89 long length ATTRIBUTE_UNUSED;
90 char *filename ATTRIBUTE_UNUSED;
98 static FILE *stdoutput;
101 output_file_create (name)
104 if (name[0] == '-' && name[1] == '\0')
110 stdoutput = fopen (name, FOPEN_WB);
111 if (stdoutput == NULL)
113 as_perror (_("FATAL: can't create %s"), name);
119 output_file_close (filename)
122 if (EOF == fclose (stdoutput))
124 as_perror (_("FATAL: can't close %s"), filename);
133 output_file_append (where, length, filename)
138 for (; length; length--, where++)
140 (void) putc (*where, stdoutput);
142 if (ferror (stdoutput))
143 /* if ( EOF == (putc( *where, stdoutput )) ) */
145 as_perror (_("Failed to emit an object byte"), filename);
146 as_fatal (_("can't continue"));