]>
Commit | Line | Data |
---|---|---|
fecd2382 RP |
1 | /* output-file.c - Deal with the output file |
2 | Copyright (C) 1987, 1990, 1991 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 | /* static const char rcsid[] = "$Id$"; */ | |
21 | ||
22 | /* | |
23 | * Confines all details of emitting object bytes to this module. | |
24 | * All O/S specific crocks should live here. | |
25 | * What we lose in "efficiency" we gain in modularity. | |
26 | * Note we don't need to #include the "as.h" file. No common coupling! | |
27 | */ | |
28 | ||
29 | /* note that we do need config info. xoxorich. */ | |
30 | ||
31 | /* #include "style.h" */ | |
32 | #include <stdio.h> | |
33 | ||
34 | #include "as.h" | |
35 | ||
36 | #include "output-file.h" | |
37 | ||
38 | static FILE *stdoutput; | |
39 | ||
40 | void output_file_create(name) | |
41 | char *name; | |
42 | { | |
43 | if(name[0]=='-' && name[1]=='\0') | |
44 | stdoutput=stdout; | |
45 | else if ( ! (stdoutput = fopen( name, "w" )) ) | |
46 | { | |
47 | as_perror ("FATAL: Can't create %s", name); | |
48 | exit(42); | |
49 | } | |
50 | } /* output_file_create() */ | |
51 | ||
52 | ||
53 | ||
54 | void output_file_close(filename) | |
55 | char *filename; | |
56 | { | |
57 | if ( EOF == fclose( stdoutput ) ) | |
58 | { | |
59 | as_perror ("FATAL: Can't close %s", filename); | |
60 | exit(42); | |
61 | } | |
62 | stdoutput = NULL; /* Trust nobody! */ | |
63 | } /* output_file_close() */ | |
64 | ||
65 | void output_file_append(where, length, filename) | |
66 | char *where; | |
67 | long length; | |
68 | char *filename; | |
69 | { | |
70 | ||
71 | for (; length; length--,where++) | |
72 | { | |
73 | (void)putc(*where,stdoutput); | |
74 | if(ferror(stdoutput)) | |
75 | /* if ( EOF == (putc( *where, stdoutput )) ) */ | |
76 | { | |
77 | as_perror("Failed to emit an object byte", filename); | |
78 | as_fatal("Can't continue"); | |
79 | } | |
80 | } | |
81 | } /* output_file_append() */ | |
82 | ||
83 | /* end: output-file.c */ |