Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* output-file.c - Deal with the output file |
6f2750fe | 2 | Copyright (C) 1987-2016 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
ec2655a6 | 8 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
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 | |
4b4da160 NC |
18 | the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | 02110-1301, USA. */ | |
252b5132 | 20 | |
252b5132 | 21 | #include "as.h" |
252b5132 RH |
22 | #include "output-file.h" |
23 | ||
252b5132 RH |
24 | #ifndef TARGET_MACH |
25 | #define TARGET_MACH 0 | |
26 | #endif | |
252b5132 | 27 | |
252b5132 RH |
28 | bfd *stdoutput; |
29 | ||
30 | void | |
3b4dbbbf | 31 | output_file_create (const char *name) |
252b5132 RH |
32 | { |
33 | if (name[0] == '-' && name[1] == '\0') | |
0e389e77 | 34 | as_fatal (_("can't open a bfd on stdout %s"), name); |
f740e790 | 35 | |
252b5132 RH |
36 | else if (!(stdoutput = bfd_openw (name, TARGET_FORMAT))) |
37 | { | |
885afe7b AM |
38 | bfd_error_type err = bfd_get_error (); |
39 | ||
40 | if (err == bfd_error_invalid_target) | |
41 | as_fatal (_("selected target format '%s' unknown"), TARGET_FORMAT); | |
e7bd9ea0 | 42 | else |
885afe7b | 43 | as_fatal (_("can't create %s: %s"), name, bfd_errmsg (err)); |
252b5132 | 44 | } |
f740e790 | 45 | |
252b5132 | 46 | bfd_set_format (stdoutput, bfd_object); |
252b5132 | 47 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, TARGET_MACH); |
252b5132 RH |
48 | if (flag_traditional_format) |
49 | stdoutput->flags |= BFD_TRADITIONAL_FORMAT; | |
50 | } | |
51 | ||
52 | void | |
3b4dbbbf | 53 | output_file_close (const char *filename) |
252b5132 | 54 | { |
df3ca5a3 NC |
55 | bfd_boolean res; |
56 | ||
57 | if (stdoutput == NULL) | |
58 | return; | |
34bca508 | 59 | |
252b5132 | 60 | /* Close the bfd. */ |
2ae08483 L |
61 | if (had_errors ()) |
62 | res = bfd_cache_close_all (); | |
63 | else | |
64 | res = bfd_close (stdoutput); | |
df3ca5a3 NC |
65 | |
66 | /* Prevent an infinite loop - if the close failed we will call as_fatal | |
67 | which will call xexit() which may call this function again... */ | |
68 | stdoutput = NULL; | |
69 | ||
70 | if (! res) | |
885afe7b AM |
71 | as_fatal (_("can't close %s: %s"), filename, |
72 | bfd_errmsg (bfd_get_error ())); | |
252b5132 | 73 | } |