1 /* output-file.c - Deal with the output file
2 Copyright (C) 1987, 90, 91, 93, 92, 94, 95, 96, 1998
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
);
59 if (flag_traditional_format
)
60 stdoutput
->flags
|= BFD_TRADITIONAL_FORMAT
;
64 output_file_close (filename
)
69 if (bfd_close (stdoutput
) == 0)
71 bfd_perror (filename
);
72 as_perror (_("FATAL: Can't close %s\n"), filename
);
76 /* Close the bfd without getting bfd to write out anything by itself */
77 if (bfd_close_all_done (stdoutput
) == 0)
79 as_perror (_("FATAL: Can't close %s\n"), filename
);
83 stdoutput
= NULL
; /* Trust nobody! */
88 output_file_append (where
, length
, filename
)
89 char *where ATTRIBUTE_UNUSED
;
90 long length ATTRIBUTE_UNUSED
;
91 char *filename ATTRIBUTE_UNUSED
;
99 static FILE *stdoutput
;
102 output_file_create (name
)
105 if (name
[0] == '-' && name
[1] == '\0')
111 stdoutput
= fopen (name
, "wb");
113 /* Some systems don't grok "b" in fopen modes. */
114 if (stdoutput
== NULL
)
115 stdoutput
= fopen (name
, "w");
117 if (stdoutput
== NULL
)
119 as_perror (_("FATAL: Can't create %s"), name
);
125 output_file_close (filename
)
128 if (EOF
== fclose (stdoutput
))
130 as_perror (_("FATAL: Can't close %s"), filename
);
133 stdoutput
= NULL
; /* Trust nobody! */
137 output_file_append (where
, length
, filename
)
142 for (; length
; length
--, where
++)
144 (void) putc (*where
, stdoutput
);
145 if (ferror (stdoutput
))
146 /* if ( EOF == (putc( *where, stdoutput )) ) */
148 as_perror (_("Failed to emit an object byte"), filename
);
149 as_fatal (_("Can't continue"));
156 /* end of output-file.c */