1 /* output-file.c - Deal with the output file
2 Copyright (C) 1987, 90, 91, 93, 92, 94, 95, 1996
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 02111-1307, USA. */
25 #include "output-file.h"
43 output_file_create (name)
46 if (name[0] == '-' && name[1] == '\0')
48 as_fatal ("Can't open a bfd on stdout %s ", name);
50 else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT)))
52 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);
62 output_file_close (filename)
67 if (bfd_close (stdoutput) == 0)
69 bfd_perror (filename);
70 as_perror ("FATAL: Can't close %s\n", filename);
74 /* Close the bfd without getting bfd to write out anything by itself */
75 if (bfd_close_all_done (stdoutput) == 0)
77 as_perror ("FATAL: Can't close %s\n", filename);
81 stdoutput = NULL; /* Trust nobody! */
86 output_file_append (where, length, filename)
97 static FILE *stdoutput;
100 output_file_create (name)
103 if (name[0] == '-' && name[1] == '\0')
109 stdoutput = fopen (name, "wb");
111 /* Some systems don't grok "b" in fopen modes. */
112 if (stdoutput == NULL)
113 stdoutput = fopen (name, "w");
115 if (stdoutput == NULL)
117 as_perror ("FATAL: Can't create %s", name);
123 output_file_close (filename)
126 if (EOF == fclose (stdoutput))
128 as_perror ("FATAL: Can't close %s", filename);
131 stdoutput = NULL; /* Trust nobody! */
135 output_file_append (where, length, filename)
140 for (; length; length--, where++)
142 (void) putc (*where, stdoutput);
143 if (ferror (stdoutput))
144 /* if ( EOF == (putc( *where, stdoutput )) ) */
146 as_perror ("Failed to emit an object byte", filename);
147 as_fatal ("Can't continue");
154 /* end of output-file.c */