2005-10-05 Paolo Bonzini <bonzini@gnu.org>
[deliverable/binutils-gdb.git] / binutils / bucomm.c
index d469bc14985700d1983bef1fe8597bd3294b1ce9..a2caa2f01c1307e7a33ff5057861bffbab55c73c 100644 (file)
@@ -16,8 +16,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 \f
 /* We might put this in a library someday so it could be dynamically
    loaded, but for now it's not necessary.  */
@@ -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
@@ -65,7 +66,7 @@ bfd_fatal (const char *string)
   xexit (1);
 }
 
-static void
+void
 report (const char * format, va_list args)
 {
   fprintf (stderr, "%s: ", program_name);
@@ -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;
+}
This page took 0.024798 seconds and 4 git commands to generate.