* dwarf2dbg.c: Include safe-ctype.h.
[deliverable/binutils-gdb.git] / binutils / bucomm.c
index 237f934fe8ccb018bcb12827f2bdbcdcc2c47638..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
@@ -38,18 +39,17 @@ typedef long time_t;
 #endif
 #endif
 
-static const char * endian_string PARAMS ((enum bfd_endian));
-static int display_target_list PARAMS ((void));
-static int display_info_table PARAMS ((int, int));
-static int display_target_tables PARAMS ((void));
+static const char * endian_string (enum bfd_endian);
+static int display_target_list (void);
+static int display_info_table (int, int);
+static int display_target_tables (void);
 \f
 /* Error reporting.  */
 
 char *program_name;
 
 void
-bfd_nonfatal (string)
-     const char *string;
+bfd_nonfatal (const char *string)
 {
   const char *errmsg = bfd_errmsg (bfd_get_error ());
 
@@ -60,17 +60,14 @@ bfd_nonfatal (string)
 }
 
 void
-bfd_fatal (string)
-     const char *string;
+bfd_fatal (const char *string)
 {
   bfd_nonfatal (string);
   xexit (1);
 }
 
 void
-report (format, args)
-     const char * format;
-     va_list args;
+report (const char * format, va_list args)
 {
   fprintf (stderr, "%s: ", program_name);
   vfprintf (stderr, format, args);
@@ -104,7 +101,7 @@ non_fatal VPARAMS ((const char *format, ...))
    different target.  */
 
 void
-set_default_bfd_target ()
+set_default_bfd_target (void)
 {
   /* The macro TARGET is defined by Makefile.  */
   const char *target = TARGET;
@@ -119,8 +116,7 @@ set_default_bfd_target ()
    the possible matching targets.  */
 
 void
-list_matching_formats (p)
-     char **p;
+list_matching_formats (char **p)
 {
   fprintf (stderr, _("%s: Matching formats:"), program_name);
   while (*p)
@@ -131,9 +127,7 @@ list_matching_formats (p)
 /* List the supported targets.  */
 
 void
-list_supported_targets (name, f)
-     const char *name;
-     FILE *f;
+list_supported_targets (const char *name, FILE *f)
 {
   int t;
   const char **targ_names = bfd_target_list ();
@@ -152,9 +146,7 @@ list_supported_targets (name, f)
 /* List the supported architectures.  */
 
 void
-list_supported_architectures (name, f)
-     const char *name;
-     FILE *f;
+list_supported_architectures (const char *name, FILE *f)
 {
   const char **arch;
 
@@ -172,8 +164,7 @@ list_supported_architectures (name, f)
 #define LONGEST_ARCH sizeof ("powerpc:common")
 
 static const char *
-endian_string (endian)
-     enum bfd_endian endian;
+endian_string (enum bfd_endian endian)
 {
   switch (endian)
     {
@@ -187,7 +178,7 @@ endian_string (endian)
    by its endianness and the architectures it supports.  */
 
 static int
-display_target_list ()
+display_target_list (void)
 {
   char *dummy_name;
   int t;
@@ -239,9 +230,7 @@ display_target_list ()
    architectures down).  */
 
 static int
-display_info_table (first, last)
-     int first;
-     int last;
+display_info_table (int first, int last)
 {
   int t;
   int a;
@@ -316,7 +305,7 @@ display_info_table (first, last)
    BFD has been configured to support.  */
 
 static int
-display_target_tables ()
+display_target_tables (void)
 {
   int t;
   int columns;
@@ -355,7 +344,7 @@ display_target_tables ()
 }
 
 int
-display_info ()
+display_info (void)
 {
   printf (_("BFD header file version %s\n"), BFD_VERSION_STRING);
   if (! display_target_list () || ! display_target_tables ())
@@ -369,10 +358,7 @@ display_info ()
    Mode       User\tGroup\tSize\tDate               Name */
 
 void
-print_arelt_descr (file, abfd, verbose)
-     FILE *file;
-     bfd *abfd;
-     bfd_boolean verbose;
+print_arelt_descr (FILE *file, bfd *abfd, bfd_boolean verbose)
 {
   struct stat buf;
 
@@ -403,8 +389,7 @@ print_arelt_descr (file, abfd, verbose)
 /* Return the name of a temporary file in the same directory as FILENAME.  */
 
 char *
-make_tempname (filename)
-     char *filename;
+make_tempname (char *filename)
 {
   static char template[] = "stXXXXXX";
   char *tmpname;
@@ -454,9 +439,7 @@ make_tempname (filename)
    parsed.  */
 
 bfd_vma
-parse_vma (s, arg)
-     const char *s;
-     const char *arg;
+parse_vma (const char *s, const char *arg)
 {
   bfd_vma ret;
   const char *end;
@@ -468,3 +451,63 @@ parse_vma (s, arg)
 
   return ret;
 }
+
+/* Returns the size of the named file.  If the file does not
+   exist, or if it is not a real file, then a suitable non-fatal
+   error message is printed and zero is returned.  */
+
+off_t
+get_file_size (const char * file_name)
+{
+  struct stat statbuf;
+  
+  if (stat (file_name, &statbuf) < 0)
+    {
+      if (errno == ENOENT)
+       non_fatal (_("'%s': No such file"), file_name);
+      else
+       non_fatal (_("Warning: could not locate '%s'.  reason: %s"),
+                  file_name, strerror (errno));
+    }  
+  else if (! S_ISREG (statbuf.st_mode))
+    non_fatal (_("Warning: '%s' is not an ordinary file"), file_name);
+  else
+    return statbuf.st_size;
+
+  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.030779 seconds and 4 git commands to generate.