Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / usr.bin / as / output-file.c
1 /* output-file.c -  Deal with the output file
2    Copyright (C) 1987, 1990, 1991, 1992 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 2, 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  * $FreeBSD: src/gnu/usr.bin/as/output-file.c,v 1.6 1999/08/27 23:34:20 peter Exp $
27  * $DragonFly: src/gnu/usr.bin/as/Attic/output-file.c,v 1.2 2003/06/17 04:25:44 dillon Exp $
28  */
29
30 /* note that we do need config info.  xoxorich. */
31
32 #include <stdio.h>
33
34 #include "as.h"
35
36 #include "output-file.h"
37 #ifdef BFD_HEADERS
38 #include "bfd.h"
39 bfd *stdoutput;
40 void output_file_create(name)
41 char *name;
42 {
43         if (name[0] == '-' && name[1] == '\0')  {
44                 as_perror("FATAL: Can't open a bfd on stdout %s ", name);
45         }
46         else if ( ! (stdoutput = bfd_openw( name, TARGET_FORMAT )) )
47             {
48                     as_perror ("FATAL: Can't create %s", name);
49                     exit(42);
50             }
51         bfd_set_format(stdoutput, bfd_object);
52 }
53 /* output_file_create() */
54
55
56 void output_file_close(filename)
57 char *filename;
58 {
59         /* Close the bfd without getting bfd to write out anything by itself */
60         if ( bfd_close_all_done( stdoutput ) == 0 )
61             {
62                     as_perror ("FATAL: Can't close %s\n", filename);
63                     exit(42);
64             }
65         stdoutput = NULL;               /* Trust nobody! */
66 }                               /* output_file_close() */
67
68 void output_file_append(where, length, filename)
69 char *where;
70 long length;
71 char *filename;
72 {
73         abort(); /* Never do this */
74 }
75
76 #else
77
78 static FILE *stdoutput;
79
80 void output_file_create(name)
81 char *name;
82 {
83         if (name[0] == '-' && name[1] == '\0')
84             stdoutput=stdout;
85         else if (!(stdoutput = fopen(name, "wb"))) {
86                 as_perror("FATAL: Can't create %s", name);
87                 exit(42);
88         }
89 } /* output_file_create() */
90
91
92
93 void output_file_close(filename)
94 char *filename;
95 {
96         if (EOF == fclose(stdoutput)) {
97                 as_perror ("FATAL: Can't close %s", filename);
98                 exit(42);
99         }
100         stdoutput = NULL;               /* Trust nobody! */
101 } /* output_file_close() */
102
103 void output_file_append(where, length, filename)
104 char *where;
105 long length;
106 char *filename;
107 {
108
109         for (; length; length--, where++) {
110                 (void) putc(*where, stdoutput);
111                 if (ferror(stdoutput))
112                     /* if ( EOF == (putc( *where, stdoutput )) ) */
113                     {
114                             as_perror("Failed to emit an object byte", filename);
115                             as_fatal("Can't continue");
116                     }
117         }
118 } /* output_file_append() */
119 #endif
120
121 /* end of output-file.c */