1 /* bucomm.c -- Bin Utils COMmon code.
2 Copyright (C) 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* We might put this in a library someday so it could be dynamically
21 loaded, but for now it's not necessary */
27 char *target = NULL; /* default as late as possible */
29 /* Yes, this is what atexit is for, but that isn't guaranteed yet.
30 And yes, I know this isn't as good, but it does what is needed just fine */
31 void (*exit_handler) ();
41 DEFUN(bfd_fatal,(string),
44 const char *errmsg = bfd_errmsg (bfd_error);
47 fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
49 fprintf (stderr, "%s: %s\n", program_name, errmsg);
51 if (NULL != exit_handler) (*exit_handler) ();
55 #if 0 /* !defined(NO_STDARG) */
62 va_start (args, Format);
63 vfprintf (stderr, Format, args);
65 (void) putc ('\n', stderr);
66 if (NULL != exit_handler) (*exit_handler) ();
77 Format = va_arg(args, char *);
78 vfprintf (stderr, Format, args);
80 (void) putc ('\n', stderr);
81 if (NULL != exit_handler) (*exit_handler) ();
87 /** Display the archive header for an element as if it were an ls -l listing */
89 /* Mode User\tGroup\tSize\tDate Name */
92 DEFUN(print_arelt_descr,(file, abfd, verbose),
102 if (bfd_stat_arch_elt (abfd, &buf) == 0) { /* if not, huh? */
105 long when = buf.st_mtime;
106 CONST char *ctime_result = (CONST char *)ctime (&when);
108 /* Posix format: skip weekday and seconds from ctime output. */
109 sprintf(timebuf, "%.12s %.4s", ctime_result+4, ctime_result+20);
111 mode_string (buf.st_mode, modebuf);
113 /* Posix 1003.2/D11 says to skip first character (entry type). */
114 fprintf (file, "%s %d/%d %6ld %s ", modebuf+1, buf.st_uid, buf.st_gid, buf.st_size, timebuf);
118 fprintf (file, "%s\n",abfd->filename);
121 /* Like malloc but get fatal error if memory is exhausted. */
126 register char *result = malloc (size);
127 if (result == (char *) NULL && size != 0) {
128 fatal ("virtual memory exhausted");
134 /* Like realloc but get fatal error if memory is exhausted. */
140 register char *result = realloc (ptr, size);
141 if (result == 0 && size != 0) {
142 fatal ("virtual memory exhausted");