summaryrefslogtreecommitdiff
path: root/binutils/bucomm.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl@lucon.org>2005-06-14 13:26:42 +0000
committerH.J. Lu <hjl@lucon.org>2005-06-14 13:26:42 +0000
commite2b4679c0267da67fe7498ab3666a63276beb0d4 (patch)
treeccede286481b2a9faf8e741988d34a572a054aa1 /binutils/bucomm.c
parentbd2cfc9a7b8f8e608d766d372b789356c9ca3ece (diff)
downloadbinutils-redhat-e2b4679c0267da67fe7498ab3666a63276beb0d4.tar.gz
2005-06-14 H.J. Lu <hongjiu.lu@intel.com>
PR 995 * ar.c (BUFSIZE): Moved to ... * bucomm.h (BUFSIZE): Here. * bucomm.c: Include <assert.h>. (bfd_get_archive_filename): New. * bucomm.h (bfd_get_archive_filename): New. * objcopy.c (copy_unknown_object): New. (copy_object): Use bfd_get_archive_filename when reporting input error. Don't call fatal on unknown arch. (copy_archive): Call copy_unknown_object on unknown format or arch.
Diffstat (limited to 'binutils/bucomm.c')
-rw-r--r--binutils/bucomm.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index f29e6663ab..a2caa2f01c 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <time.h> /* ctime, maybe time_t */
+#include <assert.h>
#ifndef HAVE_TIME_T_IN_TIME_H
#ifndef HAVE_TIME_T_IN_TYPES_H
@@ -475,3 +476,38 @@ get_file_size (const char * file_name)
return 0;
}
+
+/* Return the filename in a static buffer. */
+
+const char *
+bfd_get_archive_filename (bfd *abfd)
+{
+ static size_t curr = 0;
+ static char *buf;
+ size_t needed;
+
+ assert (abfd != NULL);
+
+ if (!abfd->my_archive)
+ return bfd_get_filename (abfd);
+
+ needed = (strlen (bfd_get_filename (abfd->my_archive))
+ + strlen (bfd_get_filename (abfd)) + 3);
+ if (needed > curr)
+ {
+ if (curr)
+ free (buf);
+ curr = needed + (needed >> 1);
+ buf = bfd_malloc (curr);
+ /* If we can't malloc, fail safe by returning just the file name.
+ This function is only used when building error messages. */
+ if (!buf)
+ {
+ curr = 0;
+ return bfd_get_filename (abfd);
+ }
+ }
+ sprintf (buf, "%s(%s)", bfd_get_filename (abfd->my_archive),
+ bfd_get_filename (abfd));
+ return buf;
+}