1 /* output-file.c - Deal with the output file
2 Copyright (C) 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 * Confines all details of emitting object bytes to this module.
22 * All O/S specific crocks should live here.
23 * What we lose in "efficiency" we gain in modularity.
24 * Note we don't need to #include the "as.h" file. No common coupling!
27 /* note that we do need config info. xoxorich. */
29 /* #include "style.h" */
34 #include "output-file.h"
38 void output_file_create(name)
41 if(name[0]=='-' && name[1]=='\0') {
42 as_perror("FATAL: Can't open a bfd on stdout %s ", name);
44 else if ( ! (stdoutput = bfd_openw( name, TARGET_FORMAT )) )
46 as_perror ("FATAL: Can't create %s", name);
49 bfd_set_format(stdoutput, bfd_object);
51 /* output_file_create() */
54 void output_file_close(filename)
57 /* Close the bfd without getting bfd to write out anything by itself */
58 if ( bfd_close_all_done( stdoutput ) == 0 )
60 as_perror ("FATAL: Can't close %s\n", filename);
63 stdoutput = NULL; /* Trust nobody! */
64 } /* output_file_close() */
66 void output_file_append(where, length, filename)
71 abort(); /* Never do this */
76 static FILE *stdoutput;
78 void output_file_create(name)
81 if(name[0]=='-' && name[1]=='\0')
83 else if ( ! (stdoutput = fopen( name, "w" )) )
85 as_perror ("FATAL: Can't create %s", name);
88 } /* output_file_create() */
92 void output_file_close(filename)
95 if ( EOF == fclose( stdoutput ) )
97 as_perror ("FATAL: Can't close %s", filename);
100 stdoutput = NULL; /* Trust nobody! */
101 } /* output_file_close() */
103 void output_file_append(where, length, filename)
109 for (; length; length--,where++)
111 (void)putc(*where,stdoutput);
112 if(ferror(stdoutput))
113 /* if ( EOF == (putc( *where, stdoutput )) ) */
115 as_perror("Failed to emit an object byte", filename);
116 as_fatal("Can't continue");
119 } /* output_file_append() */
122 /* end of output-file.c */