* chew.c (paramstuff, outputdots, perform, bang and usage): Remove
[binutils.git] / gas / output-file.c
blob531e35fa691e7f4e6ffddf167ccc5a18a5b58812
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)
10 any later version.
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
20 02111-1307, USA. */
22 #include <stdio.h>
24 #include "as.h"
26 #include "output-file.h"
28 #ifdef BFD_HEADERS
29 #define USE_BFD
30 #endif
32 #ifdef BFD_ASSEMBLER
33 #define USE_BFD
34 #ifndef TARGET_MACH
35 #define TARGET_MACH 0
36 #endif
37 #endif
39 #ifdef USE_BFD
40 #include "bfd.h"
41 bfd *stdoutput;
43 void
44 output_file_create (name)
45 char *name;
47 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);
53 exit (EXIT_FAILURE);
56 bfd_set_format (stdoutput, bfd_object);
57 #ifdef BFD_ASSEMBLER
58 bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH);
59 #endif
60 if (flag_traditional_format)
61 stdoutput->flags |= BFD_TRADITIONAL_FORMAT;
64 void
65 output_file_close (filename)
66 char *filename;
68 #ifdef BFD_ASSEMBLER
69 /* Close the bfd. */
70 if (bfd_close (stdoutput) == 0)
72 bfd_perror (filename);
73 as_perror (_("FATAL: can't close %s\n"), filename);
74 exit (EXIT_FAILURE);
76 #else
77 /* Close the bfd without getting bfd to write out anything by itself. */
78 if (bfd_close_all_done (stdoutput) == 0)
80 as_perror (_("FATAL: can't close %s\n"), filename);
81 exit (EXIT_FAILURE);
83 #endif
84 stdoutput = NULL; /* Trust nobody! */
87 #ifndef BFD_ASSEMBLER
88 void
89 output_file_append (where, length, filename)
90 char *where ATTRIBUTE_UNUSED;
91 long length ATTRIBUTE_UNUSED;
92 char *filename ATTRIBUTE_UNUSED;
94 abort ();
96 #endif
98 #else
100 static FILE *stdoutput;
102 void
103 output_file_create (name)
104 char *name;
106 if (name[0] == '-' && name[1] == '\0')
108 stdoutput = stdout;
109 return;
112 stdoutput = fopen (name, FOPEN_WB);
113 if (stdoutput == NULL)
115 as_perror (_("FATAL: can't create %s"), name);
116 exit (EXIT_FAILURE);
120 void
121 output_file_close (filename)
122 char *filename;
124 if (EOF == fclose (stdoutput))
126 as_perror (_("FATAL: can't close %s"), filename);
127 exit (EXIT_FAILURE);
130 /* Trust nobody! */
131 stdoutput = NULL;
134 void
135 output_file_append (where, length, filename)
136 char * where;
137 long length;
138 char * filename;
140 for (; length; length--, where++)
142 (void) putc (*where, stdoutput);
144 if (ferror (stdoutput))
145 /* if ( EOF == (putc( *where, stdoutput )) ) */
147 as_perror (_("Failed to emit an object byte"), filename);
148 as_fatal (_("can't continue"));
153 #endif