1 /* output-file.c - Deal with the output file
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001, 2003
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 if (bfd_get_error () == bfd_error_invalid_target
)
52 as_perror (_("Selected target format '%s' unknown"), TARGET_FORMAT
);
54 as_perror (_("FATAL: can't create %s"), name
);
58 bfd_set_format (stdoutput
, bfd_object
);
60 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, TARGET_MACH
);
62 if (flag_traditional_format
)
63 stdoutput
->flags
|= BFD_TRADITIONAL_FORMAT
;
67 output_file_close (char *filename
)
71 if (bfd_close (stdoutput
) == 0)
73 bfd_perror (filename
);
74 as_perror (_("FATAL: can't close %s\n"), filename
);
78 /* Close the bfd without getting bfd to write out anything by itself. */
79 if (bfd_close_all_done (stdoutput
) == 0)
81 as_perror (_("FATAL: can't close %s\n"), filename
);
85 stdoutput
= NULL
; /* Trust nobody! */
90 output_file_append (char *where ATTRIBUTE_UNUSED
,
91 long length ATTRIBUTE_UNUSED
,
92 char *filename ATTRIBUTE_UNUSED
)
100 static FILE *stdoutput
;
103 output_file_create (char *name
)
105 if (name
[0] == '-' && name
[1] == '\0')
111 stdoutput
= fopen (name
, FOPEN_WB
);
112 if (stdoutput
== NULL
)
115 bfd_set_error (bfd_error_system_call
);
117 as_perror (_("FATAL: can't create %s"), name
);
123 output_file_close (char *filename
)
125 if (EOF
== fclose (stdoutput
))
128 bfd_set_error (bfd_error_system_call
);
130 as_perror (_("FATAL: can't close %s"), filename
);
139 output_file_append (char * where
, long length
, char * filename
)
141 for (; length
; length
--, where
++)
143 (void) putc (*where
, stdoutput
);
145 if (ferror (stdoutput
))
148 bfd_set_error (bfd_error_system_call
);
150 as_perror (_("Failed to emit an object byte"), filename
);
151 as_fatal (_("can't continue"));