*** empty log message ***
[deliverable/binutils-gdb.git] / binutils / rescoff.c
index 6c7f21b15e3d4cd18a6b8d9169c4ef5c67e5bfdb..fdd9aad9982e5ac8d19923f90054d77305f671bd 100644 (file)
@@ -1,5 +1,6 @@
 /* rescoff.c -- read and write resources in Windows COFF files.
-   Copyright 1997 Free Software Foundation, Inc.
+   Copyright 1997, 1998, 1999, 2000, 2003
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of GNU Binutils.
@@ -16,8 +17,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.  */
 
 /* This file contains function that read and write Windows resources
    in COFF files.  */
@@ -102,20 +103,17 @@ struct extern_res_data
 
 /* Local functions.  */
 
-static void overrun PARAMS ((const struct coff_file_info *, const char *));
+static void overrun (const struct coff_file_info *, const char *);
 static struct res_directory *read_coff_res_dir
-  PARAMS ((const bfd_byte *, const struct coff_file_info *,
-          const struct res_id *, int));
+  (const bfd_byte *, const struct coff_file_info *,
+   const struct res_id *, int);
 static struct res_resource *read_coff_data_entry
-  PARAMS ((const bfd_byte *, const struct coff_file_info *,
-          const struct res_id *));
+  (const bfd_byte *, const struct coff_file_info *, const struct res_id *);
 \f
 /* Read the resources in a COFF file.  */
 
 struct res_directory *
-read_coff_rsrc (filename, target)
-     const char *filename;
-     const char *target;
+read_coff_rsrc (const char *filename, const char *target)
 {
   bfd *abfd;
   char **matching;
@@ -124,6 +122,9 @@ read_coff_rsrc (filename, target)
   bfd_byte *data;
   struct coff_file_info finfo;
 
+  if (filename == NULL)
+    fatal (_("filename required for COFF input"));
+
   abfd = bfd_openr (filename, target);
   if (abfd == NULL)
     bfd_fatal (filename);
@@ -139,16 +140,14 @@ read_coff_rsrc (filename, target)
   sec = bfd_get_section_by_name (abfd, ".rsrc");
   if (sec == NULL)
     {
-      fprintf (stderr, "%s: %s: no resource section\n", program_name,
-              filename);
-      xexit (1);
+      fatal (_("%s: no resource section"), filename);
     }
 
   size = bfd_section_size (abfd, sec);
   data = (bfd_byte *) res_alloc (size);
 
   if (! bfd_get_section_contents (abfd, sec, data, 0, size))
-    bfd_fatal ("can't read resource section");
+    bfd_fatal (_("can't read resource section"));
 
   finfo.filename = filename;
   finfo.data = data;
@@ -170,21 +169,16 @@ read_coff_rsrc (filename, target)
 /* Give an error if we are out of bounds.  */
 
 static void
-overrun (finfo, msg)
-     const struct coff_file_info *finfo;
-     const char *msg;
+overrun (const struct coff_file_info *finfo, const char *msg)
 {
-  fatal ("%s: %s: address out of bounds", finfo->filename, msg);
+  fatal (_("%s: %s: address out of bounds"), finfo->filename, msg);
 }
 
 /* Read a resource directory.  */
 
 static struct res_directory *
-read_coff_res_dir (data, finfo, type, level)
-     const bfd_byte *data;
-     const struct coff_file_info *finfo;
-     const struct res_id *type;
-     int level;
+read_coff_res_dir (const bfd_byte *data, const struct coff_file_info *finfo,
+                  const struct res_id *type, int level)
 {
   const struct extern_res_directory *erd;
   struct res_directory *rd;
@@ -192,8 +186,8 @@ read_coff_res_dir (data, finfo, type, level)
   struct res_entry **pp;
   const struct extern_res_entry *ere;
 
-  if (finfo->data_end - data < sizeof (struct extern_res_directory))
-    overrun (finfo, "directory");
+  if ((size_t) (finfo->data_end - data) < sizeof (struct extern_res_directory))
+    overrun (finfo, _("directory"));
 
   erd = (const struct extern_res_directory *) data;
 
@@ -221,7 +215,7 @@ read_coff_res_dir (data, finfo, type, level)
       int length, j;
 
       if ((const bfd_byte *) ere >= finfo->data_end)
-       overrun (finfo, "named directory entry");
+       overrun (finfo, _("named directory entry"));
 
       name = getfi_32 (finfo, ere->name);
       rva = getfi_32 (finfo, ere->rva);
@@ -229,8 +223,8 @@ read_coff_res_dir (data, finfo, type, level)
       /* For some reason the high bit in NAME is set.  */
       name &=~ 0x80000000;
 
-      if (name > finfo->data_end - finfo->data)
-       overrun (finfo, "directory entry name");
+      if (name > (size_t) (finfo->data_end - finfo->data))
+       overrun (finfo, _("directory entry name"));
 
       ers = finfo->data + name;
 
@@ -249,16 +243,16 @@ read_coff_res_dir (data, finfo, type, level)
       if ((rva & 0x80000000) != 0)
        {
          rva &=~ 0x80000000;
-         if (rva >= finfo->data_end - finfo->data)
-           overrun (finfo, "named subdirectory");
+         if (rva >= (size_t) (finfo->data_end - finfo->data))
+           overrun (finfo, _("named subdirectory"));
          re->subdir = 1;
          re->u.dir = read_coff_res_dir (finfo->data + rva, finfo, type,
                                         level + 1);
        }
       else
        {
-         if (rva >= finfo->data_end - finfo->data)
-           overrun (finfo, "named resource");
+         if (rva >= (size_t) (finfo->data_end - finfo->data))
+           overrun (finfo, _("named resource"));
          re->subdir = 0;
          re->u.res = read_coff_data_entry (finfo->data + rva, finfo, type);
        }
@@ -273,7 +267,7 @@ read_coff_res_dir (data, finfo, type, level)
       struct res_entry *re;
 
       if ((const bfd_byte *) ere >= finfo->data_end)
-       overrun (finfo, "ID directory entry");
+       overrun (finfo, _("ID directory entry"));
 
       name = getfi_32 (finfo, ere->name);
       rva = getfi_32 (finfo, ere->rva);
@@ -289,16 +283,16 @@ read_coff_res_dir (data, finfo, type, level)
       if ((rva & 0x80000000) != 0)
        {
          rva &=~ 0x80000000;
-         if (rva >= finfo->data_end - finfo->data)
-           overrun (finfo, "ID subdirectory");
+         if (rva >= (size_t) (finfo->data_end - finfo->data))
+           overrun (finfo, _("ID subdirectory"));
          re->subdir = 1;
          re->u.dir = read_coff_res_dir (finfo->data + rva, finfo, type,
                                         level + 1);
        }
       else
        {
-         if (rva >= finfo->data_end - finfo->data)
-           overrun (finfo, "ID resource");
+         if (rva >= (size_t) (finfo->data_end - finfo->data))
+           overrun (finfo, _("ID resource"));
          re->subdir = 0;
          re->u.res = read_coff_data_entry (finfo->data + rva, finfo, type);
        }
@@ -313,10 +307,7 @@ read_coff_res_dir (data, finfo, type, level)
 /* Read a resource data entry.  */
 
 static struct res_resource *
-read_coff_data_entry (data, finfo, type)
-     const bfd_byte *data;
-     const struct coff_file_info *finfo;
-     const struct res_id *type;
+read_coff_data_entry (const bfd_byte *data, const struct coff_file_info *finfo, const struct res_id *type)
 {
   const struct extern_res_data *erd;
   struct res_resource *r;
@@ -324,23 +315,23 @@ read_coff_data_entry (data, finfo, type)
   const bfd_byte *resdata;
 
   if (type == NULL)
-    fatal ("resource type unknown");
+    fatal (_("resource type unknown"));
 
-  if (finfo->data_end - data < sizeof (struct extern_res_data))
-    overrun (finfo, "data entry");
+  if ((size_t) (finfo->data_end - data) < sizeof (struct extern_res_data))
+    overrun (finfo, _("data entry"));
 
   erd = (const struct extern_res_data *) data;
 
   size = getfi_32 (finfo, erd->size);
   rva = getfi_32 (finfo, erd->rva);
   if (rva < finfo->secaddr
-      || rva - finfo->secaddr >= finfo->data_end - finfo->data)
-    overrun (finfo, "resource data");
+      || rva - finfo->secaddr >= (size_t) (finfo->data_end - finfo->data))
+    overrun (finfo, _("resource data"));
 
   resdata = finfo->data + (rva - finfo->secaddr);
 
-  if (size > finfo->data_end - resdata)
-    overrun (finfo, "resource data size");
+  if (size > (size_t) (finfo->data_end - resdata))
+    overrun (finfo, _("resource data size"));
 
   r = bin_to_res (*type, resdata, size, finfo->big_endian);
 
@@ -407,12 +398,12 @@ struct coff_write_info
   ((cwi->big_endian) ? bfd_putb32 ((v), (s)) : bfd_putl32 ((v), (s)))
 
 static void coff_bin_sizes
-  PARAMS ((const struct res_directory *, struct coff_write_info *));
-static unsigned char *coff_alloc PARAMS ((struct bindata_build *, size_t));
+  (const struct res_directory *, struct coff_write_info *);
+static unsigned char *coff_alloc (struct bindata_build *, size_t);
 static void coff_to_bin
-  PARAMS ((const struct res_directory *, struct coff_write_info *));
+  (const struct res_directory *, struct coff_write_info *);
 static void coff_res_to_bin
-  PARAMS ((const struct res_resource *, struct coff_write_info *));
+  (const struct res_resource *, struct coff_write_info *);
 
 /* Write resources to a COFF file.  RESOURCES should already be
    sorted.
@@ -422,12 +413,9 @@ static void coff_res_to_bin
    would require doing the basic work of objcopy, just modifying or
    adding the .rsrc section.  */
 
-
 void
-write_coff_file (filename, target, resources)
-     const char *filename;
-     const char *target;
-     const struct res_directory *resources;
+write_coff_file (const char *filename, const char *target,
+                const struct res_directory *resources)
 {
   bfd *abfd;
   asection *sec;
@@ -435,6 +423,9 @@ write_coff_file (filename, target, resources)
   struct bindata *d;
   unsigned long length, offset;
 
+  if (filename == NULL)
+    fatal (_("filename required for COFF output"));
+
   abfd = bfd_openw (filename, target);
   if (abfd == NULL)
     bfd_fatal (filename);
@@ -442,9 +433,20 @@ write_coff_file (filename, target, resources)
   if (! bfd_set_format (abfd, bfd_object))
     bfd_fatal ("bfd_set_format");
 
+#if defined DLLTOOL_SH
+  if (! bfd_set_arch_mach (abfd, bfd_arch_sh, 0))
+    bfd_fatal ("bfd_set_arch_mach(sh)");
+#elif defined DLLTOOL_MIPS
+  if (! bfd_set_arch_mach (abfd, bfd_arch_mips, 0))
+    bfd_fatal ("bfd_set_arch_mach(mips)");
+#elif defined DLLTOOL_ARM
+  if (! bfd_set_arch_mach (abfd, bfd_arch_arm, 0))
+    bfd_fatal ("bfd_set_arch_mach(arm)");
+#else
   /* FIXME: This is obviously i386 specific.  */
   if (! bfd_set_arch_mach (abfd, bfd_arch_i386, 0))
-    bfd_fatal ("bfd_set_arch_mach");
+    bfd_fatal ("bfd_set_arch_mach(i386)");
+#endif
 
   if (! bfd_set_file_flags (abfd, HAS_SYMS | HAS_RELOC))
     bfd_fatal ("bfd_set_file_flags");
@@ -570,9 +572,8 @@ write_coff_file (filename, target, resources)
    entries.  This updates fields in CWI.  */
 
 static void
-coff_bin_sizes (resdir, cwi)
-     const struct res_directory *resdir;
-     struct coff_write_info *cwi;
+coff_bin_sizes (const struct res_directory *resdir,
+               struct coff_write_info *cwi)
 {
   const struct res_entry *re;
 
@@ -595,9 +596,7 @@ coff_bin_sizes (resdir, cwi)
 /* Allocate data for a particular list.  */
 
 static unsigned char *
-coff_alloc (bb, size)
-     struct bindata_build *bb;
-     size_t size;
+coff_alloc (struct bindata_build *bb, size_t size)
 {
   struct bindata *d;
 
@@ -620,9 +619,7 @@ coff_alloc (bb, size)
 /* Convert the resource directory RESDIR to binary.  */
 
 static void
-coff_to_bin (resdir, cwi)
-     const struct res_directory *resdir;
-     struct coff_write_info *cwi;
+coff_to_bin (const struct res_directory *resdir, struct coff_write_info *cwi)
 {
   struct extern_res_directory *erd;
   int ci, cn;
@@ -699,9 +696,7 @@ coff_to_bin (resdir, cwi)
 /* Convert the resource RES to binary.  */
 
 static void
-coff_res_to_bin (res, cwi)
-     const struct res_resource *res;
-     struct coff_write_info *cwi;
+coff_res_to_bin (const struct res_resource *res, struct coff_write_info *cwi)
 {
   arelent *r;
   struct extern_res_data *erd;
@@ -721,7 +716,7 @@ coff_res_to_bin (res, cwi)
   r->addend = 0;
   r->howto = bfd_reloc_type_lookup (cwi->abfd, BFD_RELOC_RVA);
   if (r->howto == NULL)
-    bfd_fatal ("can't get BFD_RELOC_RVA relocation type");
+    bfd_fatal (_("can't get BFD_RELOC_RVA relocation type"));
 
   cwi->relocs = xrealloc (cwi->relocs,
                          (cwi->reloc_count + 2) * sizeof (arelent *));
This page took 0.045403 seconds and 4 git commands to generate.