1
/* bucomm.c -- Bin Utils COMmon code.
2
Copyright (C) 1991, 92, 93, 94, 95, 1997 Free Software Foundation, Inc.
4
This file is part of GNU Binutils.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
21
/* We might put this in a library someday so it could be dynamically
22
loaded, but for now it's not necessary. */
25
#include <libiberty.h>
29
#include <time.h> /* ctime, maybe time_t */
31
#ifdef ANSI_PROTOTYPES
45
CONST char *errmsg = bfd_errmsg (bfd_get_error ());
48
fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
50
fprintf (stderr, "%s: %s\n", program_name, errmsg);
57
bfd_nonfatal (string);
61
#ifdef ANSI_PROTOTYPES
63
fatal (const char *format, ...)
67
fprintf (stderr, "%s: ", program_name);
68
va_start (args, format);
69
vfprintf (stderr, format, args);
82
fprintf (stderr, "%s: ", program_name);
84
Format = va_arg (args, char *);
85
vfprintf (stderr, Format, args);
92
/* Set the default BFD target based on the configured target. Doing
93
this permits the binutils to be configured for a particular target,
94
and linked against a shared BFD library which was configured for a
97
#define TARGET "elf32-i386" /* FIXME: hard-coded! */
99
set_default_bfd_target ()
101
/* The macro TARGET is defined by Makefile. */
102
const char *target = TARGET;
104
if (! bfd_set_default_target (target))
108
errmsg = (char *) xmalloc (100 + strlen (target));
109
sprintf (errmsg, "can't set BFD default target to `%s'", target);
114
/* After a false return from bfd_check_format_matches with
115
bfd_get_error () == bfd_error_file_ambiguously_recognized, print
116
the possible matching targets. */
119
list_matching_formats (p)
122
fprintf(stderr, "%s: Matching formats:", program_name);
124
fprintf(stderr, " %s", *p++);
125
fprintf(stderr, "\n");
128
/* List the supported targets. */
131
list_supported_targets (name, f)
135
extern bfd_target *bfd_target_vector[];
139
fprintf (f, "Supported targets:");
141
fprintf (f, "%s: supported targets:", name);
142
for (t = 0; bfd_target_vector[t] != NULL; t++)
143
fprintf (f, " %s", bfd_target_vector[t]->name);
147
/* Display the archive header for an element as if it were an ls -l listing:
149
Mode User\tGroup\tSize\tDate Name */
152
print_arelt_descr (file, abfd, verbose)
161
if (bfd_stat_arch_elt (abfd, &buf) == 0)
165
time_t when = buf.st_mtime;
166
CONST char *ctime_result = (CONST char *) ctime (&when);
168
/* POSIX format: skip weekday and seconds from ctime output. */
169
sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
171
mode_string (buf.st_mode, modebuf);
173
/* POSIX 1003.2/D11 says to skip first character (entry type). */
174
fprintf (file, "%s %ld/%ld %6ld %s ", modebuf + 1,
175
(long) buf.st_uid, (long) buf.st_gid,
176
(long) buf.st_size, timebuf);
180
fprintf (file, "%s\n", bfd_get_filename (abfd));
183
/* Return the name of a temporary file in the same directory as FILENAME. */
186
make_tempname (filename)
189
static char template[] = "stXXXXXX";
191
char *slash = strrchr (filename, '/');
193
#if defined (__DJGPP__) || defined (__GO32__) || defined (_WIN32)
195
slash = strrchr (filename, '\\');
198
if (slash != (char *) NULL)
204
tmpname = xmalloc (strlen (filename) + sizeof (template) + 1);
205
strcpy (tmpname, filename);
206
strcat (tmpname, "/");
207
strcat (tmpname, template);
213
tmpname = xmalloc (sizeof (template));
214
strcpy (tmpname, template);
220
/* Parse a string into a VMA, with a fatal error if it can't be
231
ret = bfd_scan_vma (s, &end, 0);
234
fprintf (stderr, "%s: %s: bad number: %s\n", program_name, arg, s);