]>
Commit | Line | Data |
---|---|---|
b886a6e3 | 1 | /* bucomm.c -- Bin Utils COMmon code. |
fb3f84c7 | 2 | Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc. |
2fa0b342 | 3 | |
096aefc0 | 4 | This file is part of GNU Binutils. |
b886a6e3 | 5 | |
096aefc0 KR |
6 | This program 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 of the License, or | |
9 | (at your option) any later version. | |
b886a6e3 | 10 | |
096aefc0 KR |
11 | This program 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. | |
b886a6e3 | 15 | |
096aefc0 KR |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | \f | |
20 | /* We might put this in a library someday so it could be dynamically | |
21 | loaded, but for now it's not necessary. */ | |
2fa0b342 | 22 | |
2fa0b342 | 23 | #include "bfd.h" |
b886a6e3 | 24 | #include "sysdep.h" |
fb3f84c7 | 25 | #include "libiberty.h" |
0886e098 SS |
26 | #include "bucomm.h" |
27 | ||
fb3f84c7 | 28 | #ifdef ANSI_PROTOTYPES |
0886e098 SS |
29 | #include <stdarg.h> |
30 | #else | |
2fa0b342 | 31 | #include <varargs.h> |
0886e098 | 32 | #endif |
2fa0b342 DHW |
33 | |
34 | char *target = NULL; /* default as late as possible */ | |
fb3f84c7 | 35 | \f |
2fa0b342 DHW |
36 | /* Error reporting */ |
37 | ||
38 | char *program_name; | |
39 | ||
40 | void | |
096aefc0 | 41 | bfd_nonfatal (string) |
0886e098 | 42 | CONST char *string; |
2fa0b342 | 43 | { |
fb3f84c7 | 44 | CONST char *errmsg = bfd_errmsg (bfd_get_error ()); |
096aefc0 | 45 | |
2fa0b342 DHW |
46 | if (string) |
47 | fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg); | |
48 | else | |
49 | fprintf (stderr, "%s: %s\n", program_name, errmsg); | |
096aefc0 | 50 | } |
2fa0b342 | 51 | |
096aefc0 KR |
52 | void |
53 | bfd_fatal (string) | |
0886e098 | 54 | CONST char *string; |
096aefc0 KR |
55 | { |
56 | bfd_nonfatal (string); | |
fb3f84c7 | 57 | xexit (1); |
2fa0b342 DHW |
58 | } |
59 | ||
fb3f84c7 | 60 | #ifdef ANSI_PROTOTYPES |
2fa0b342 | 61 | void |
0886e098 | 62 | fatal (const char *format, ...) |
2fa0b342 DHW |
63 | { |
64 | va_list args; | |
096aefc0 KR |
65 | |
66 | fprintf (stderr, "%s: ", program_name); | |
0886e098 SS |
67 | va_start (args, format); |
68 | vfprintf (stderr, format, args); | |
2fa0b342 | 69 | va_end (args); |
096aefc0 | 70 | putc ('\n', stderr); |
fb3f84c7 | 71 | xexit (1); |
2fa0b342 DHW |
72 | } |
73 | #else | |
096aefc0 KR |
74 | void |
75 | fatal (va_alist) | |
2fa0b342 DHW |
76 | va_dcl |
77 | { | |
096aefc0 KR |
78 | char *Format; |
79 | va_list args; | |
2fa0b342 | 80 | |
096aefc0 KR |
81 | fprintf (stderr, "%s: ", program_name); |
82 | va_start (args); | |
83 | Format = va_arg (args, char *); | |
84 | vfprintf (stderr, Format, args); | |
85 | va_end (args); | |
86 | putc ('\n', stderr); | |
fb3f84c7 | 87 | xexit (1); |
096aefc0 KR |
88 | } |
89 | #endif | |
fb3f84c7 ILT |
90 | |
91 | /* After a false return from bfd_check_format_matches with | |
92 | bfd_get_error () == bfd_error_file_ambiguously_recognized, print the possible | |
93 | matching targets. */ | |
94 | ||
95 | void | |
96 | list_matching_formats (p) | |
97 | char **p; | |
98 | { | |
99 | fprintf(stderr, "%s: Matching formats:", program_name); | |
100 | while (*p) | |
101 | fprintf(stderr, " %s", *p++); | |
102 | fprintf(stderr, "\n"); | |
103 | } | |
104 | ||
105 | /* List the supported targets. */ | |
106 | ||
107 | void | |
108 | list_supported_targets (name, f) | |
109 | const char *name; | |
110 | FILE *f; | |
111 | { | |
112 | extern bfd_target *bfd_target_vector[]; | |
113 | int t; | |
114 | ||
115 | if (name == NULL) | |
116 | fprintf (f, "Supported targets:"); | |
117 | else | |
118 | fprintf (f, "%s: supported targets:", name); | |
119 | for (t = 0; bfd_target_vector[t] != NULL; t++) | |
120 | fprintf (f, " %s", bfd_target_vector[t]->name); | |
121 | fprintf (f, "\n"); | |
122 | } | |
2fa0b342 | 123 | \f |
096aefc0 KR |
124 | /* Display the archive header for an element as if it were an ls -l listing: |
125 | ||
126 | Mode User\tGroup\tSize\tDate Name */ | |
2fa0b342 DHW |
127 | |
128 | void | |
096aefc0 KR |
129 | print_arelt_descr (file, abfd, verbose) |
130 | FILE *file; | |
131 | bfd *abfd; | |
132 | boolean verbose; | |
2fa0b342 DHW |
133 | { |
134 | struct stat buf; | |
2fa0b342 | 135 | |
096aefc0 KR |
136 | if (verbose) |
137 | { | |
138 | if (bfd_stat_arch_elt (abfd, &buf) == 0) | |
139 | { | |
140 | char modebuf[11]; | |
141 | char timebuf[40]; | |
0886e098 | 142 | time_t when = buf.st_mtime; |
096aefc0 KR |
143 | CONST char *ctime_result = (CONST char *) ctime (&when); |
144 | ||
145 | /* POSIX format: skip weekday and seconds from ctime output. */ | |
146 | sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20); | |
147 | ||
148 | mode_string (buf.st_mode, modebuf); | |
149 | modebuf[10] = '\0'; | |
150 | /* POSIX 1003.2/D11 says to skip first character (entry type). */ | |
fb3f84c7 ILT |
151 | fprintf (file, "%s %ld/%ld %6ld %s ", modebuf + 1, |
152 | (long) buf.st_uid, (long) buf.st_gid, | |
153 | (long) buf.st_size, timebuf); | |
096aefc0 | 154 | } |
2fa0b342 | 155 | } |
2fa0b342 | 156 | |
fb3f84c7 | 157 | fprintf (file, "%s\n", bfd_get_filename (abfd)); |
2fa0b342 | 158 | } |