#include "bfd.h"
#include "libiberty.h"
#include "bucomm.h"
#include "filenames.h"
#include <sys/stat.h>
#include <time.h>
#ifndef HAVE_TIME_T_IN_TIME_H
#ifndef HAVE_TIME_T_IN_TYPES_H
typedef long time_t;
#endif
#endif
char *program_name;
void binutils_bug_report (f)
FILE *f;
{
}
void
bfd_nonfatal (string)
CONST char *string;
{
CONST char *errmsg = bfd_errmsg (bfd_get_error ());
if (string)
fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
else
fprintf (stderr, "%s: %s\n", program_name, errmsg);
}
void
bfd_fatal (string)
CONST char *string;
{
bfd_nonfatal (string);
xexit (1);
}
void
report (format, args)
const char * format;
va_list args;
{
fprintf (stderr, "%s: ", program_name);
vfprintf (stderr, format, args);
putc ('\n', stderr);
}
void
fatal VPARAMS ((const char *format, ...))
{
VA_OPEN (args, format);
VA_FIXEDARG (args, const char *, format);
report (format, args);
VA_CLOSE (args);
xexit (1);
}
void
non_fatal VPARAMS ((const char *format, ...))
{
VA_OPEN (args, format);
VA_FIXEDARG (args, const char *, format);
report (format, args);
VA_CLOSE (args);
}
void
set_default_bfd_target ()
{
const char *target = TARGET;
if (! bfd_set_default_target (target))
fatal (_("can't set BFD default target to `%s': %s"),
target, bfd_errmsg (bfd_get_error ()));
}
void
list_matching_formats (p)
char **p;
{
fprintf (stderr, _("%s: Matching formats:"), program_name);
while (*p)
fprintf (stderr, " %s", *p++);
fputc ('\n', stderr);
}
void
list_supported_targets (name, f)
const char *name;
FILE *f;
{
extern const bfd_target *const *bfd_target_vector;
int t;
if (name == NULL)
fprintf (f, _("Supported targets:"));
else
fprintf (f, _("%s: supported targets:"), name);
for (t = 0; bfd_target_vector[t] != NULL; t++)
fprintf (f, " %s", bfd_target_vector[t]->name);
fprintf (f, "\n");
}
void
list_supported_architectures (name, f)
const char *name;
FILE *f;
{
const char** arch;
if (name == NULL)
fprintf (f, _("Supported architectures:"));
else
fprintf (f, _("%s: supported architectures:"), name);
for (arch = bfd_arch_list (); *arch; arch++)
fprintf (f, " %s", *arch);
fprintf (f, "\n");
}
void
print_arelt_descr (file, abfd, verbose)
FILE *file;
bfd *abfd;
boolean verbose;
{
struct stat buf;
if (verbose)
{
if (bfd_stat_arch_elt (abfd, &buf) == 0)
{
char modebuf[11];
char timebuf[40];
time_t when = buf.st_mtime;
CONST char *ctime_result = (CONST char *) ctime (&when);
sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
mode_string (buf.st_mode, modebuf);
modebuf[10] = '\0';
fprintf (file, "%s %ld/%ld %6ld %s ", modebuf + 1,
(long) buf.st_uid, (long) buf.st_gid,
(long) buf.st_size, timebuf);
}
}
fprintf (file, "%s\n", bfd_get_filename (abfd));
}
char *
make_tempname (filename)
char *filename;
{
static char template[] = "stXXXXXX";
char *tmpname;
char *slash = strrchr (filename, '/');
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
{
char *bslash = strrchr (filename, '\\');
if (slash == NULL || (bslash != NULL && bslash > slash))
slash = bslash;
if (slash == NULL && filename[0] != '\0' && filename[1] == ':')
slash = filename + 1;
}
#endif
if (slash != (char *) NULL)
{
char c;
c = *slash;
*slash = 0;
tmpname = xmalloc (strlen (filename) + sizeof (template) + 2);
strcpy (tmpname, filename);
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
if (tmpname[1] == ':' && tmpname[2] == '\0')
strcat (tmpname, ".");
#endif
strcat (tmpname, "/");
strcat (tmpname, template);
mktemp (tmpname);
*slash = c;
}
else
{
tmpname = xmalloc (sizeof (template));
strcpy (tmpname, template);
mktemp (tmpname);
}
return tmpname;
}
bfd_vma
parse_vma (s, arg)
const char *s;
const char *arg;
{
bfd_vma ret;
const char *end;
ret = bfd_scan_vma (s, &end, 0);
if (*end != '\0')
fatal (_("%s: bad number: %s"), arg, s);
return ret;
}