Commit | Line | Data |
---|---|---|
9c767d1a C |
1 | /* output-file.c - Deal with the output file |
2 | Copyright (C) 1987 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
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 1, or (at your option) | |
9 | any later version. | |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
20 | /* | |
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! | |
25 | */ | |
26 | ||
27 | /* #include "style.h" */ | |
28 | #include <stdio.h> | |
29 | ||
30 | void as_perror(); | |
31 | ||
32 | static FILE * | |
33 | stdoutput; | |
34 | ||
35 | void | |
36 | output_file_create (name) | |
37 | char * name; | |
38 | { | |
39 | if(name[0]=='-' && name[1]=='\0') | |
40 | stdoutput=stdout; | |
41 | else if ( ! (stdoutput = fopen( name, "w" )) ) | |
42 | { | |
43 | as_perror ("FATAL: Can't create %s", name); | |
44 | exit(42); | |
45 | } | |
46 | } | |
47 | ||
48 | ||
49 | ||
50 | void | |
51 | output_file_close (filename) | |
52 | char * filename; | |
53 | { | |
54 | if ( EOF == fclose( stdoutput ) ) | |
55 | { | |
56 | as_perror ("FATAL: Can't close %s", filename); | |
57 | exit(42); | |
58 | } | |
59 | stdoutput = NULL; /* Trust nobody! */ | |
60 | } | |
61 | ||
62 | void | |
63 | output_file_append (where, length, filename) | |
64 | char * where; | |
65 | long int length; | |
66 | char * filename; | |
67 | { | |
68 | ||
69 | for (; length; length--,where++) | |
70 | { | |
71 | (void)putc(*where,stdoutput); | |
72 | if(ferror(stdoutput)) | |
73 | /* if ( EOF == (putc( *where, stdoutput )) ) */ | |
74 | { | |
75 | as_perror("Failed to emit an object byte", filename); | |
76 | as_fatal("Can't continue"); | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
81 | /* end: output-file.c */ |