* alpha-tdep.c (alpha_register_virtual_type): Use alpha-specific
[binutils-gdb.git] / binutils / resres.c
index f79e8149e0aa89d8bc9c07fce01ab41a9fa0824d..ed2714db0050c1d4bb0ab6235fe828b7ed61c4a7 100644 (file)
@@ -1,6 +1,5 @@
 /* resres.c: read_res_file and write_res_file implementation for windres.
-
-   Copyright 1997, 1998 Free Software Foundation, Inc.
+   Copyright 1998, 1999 Free Software Foundation, Inc.
    Written by Anders Norlander <anorland@hem2.passagen.se>.
 
    This file is part of GNU Binutils.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-#include <assert.h>
-#include <stdio.h>
-#include <errno.h>
+/* FIXME: This file does not work correctly in a cross configuration.
+   It assumes that it can use fread and fwrite to read and write
+   integers.  It does no swapping.  */
 
+#include "bfd.h"
+#include "bucomm.h"
+#include "libiberty.h"
 #include "windres.h"
 
+#include <assert.h>
+#include <time.h>
+
 struct res_hdr
   {
     unsigned long data_size;
@@ -109,8 +114,6 @@ write_res_file (fn, resdir)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
   long fpos;
-  struct res_entry *e;
-  int i;
 
   filename = fn;
 
@@ -143,9 +146,7 @@ read_resource_entry (void)
   struct res_id name;
   struct res_res_info resinfo;
   struct res_hdr reshdr;
-  enum res_type rtype;
   long version;
-  long n;
   void *buff;
 
   struct res_resource *r;
@@ -210,7 +211,7 @@ write_res_directory (rd, type, name, language, level)
 
        case 2:
          /* If we're at level 2, the key of this resource is the name
-            we are going to use in the rc printout. */
+            we are going to use in the rc printout.  */
          name = &re->id;
          break;
 
@@ -218,7 +219,7 @@ write_res_directory (rd, type, name, language, level)
          /* If we're at level 3, then this key represents a language.
             Use it to update the current language.  */
          if (!re->id.named
-             && re->id.u.id != *language
+             && re->id.u.id != (unsigned long) *language
              && (re->id.u.id & 0xffff) == re->id.u.id)
            {
              *language = re->id.u.id;
@@ -258,7 +259,7 @@ write_res_resource (type, name, res, language)
      const struct res_id *type;
      const struct res_id *name;
      const struct res_resource *res;
-     int *language;
+     int *language ATTRIBUTE_UNUSED;
 {
   int rt;
 
@@ -330,7 +331,7 @@ write_res_resource (type, name, res, language)
 
   if (rt != 0
       && type != NULL
-      && (type->named || type->u.id != rt))
+      && (type->named || type->u.id != (unsigned long) rt))
     {
       fprintf (stderr, "// Unexpected resource type mismatch: ");
       res_id_print (stderr, *type, 1);
@@ -386,6 +387,8 @@ write_res_header (datasize, type, name, resinfo)
   reshdr.data_size = datasize;
   reshdr.header_size = 24 + get_id_size (type) + get_id_size (name);
 
+  reshdr.header_size = (reshdr.header_size + 3) & ~3;
+
   res_align_file ();
   write_res_data (&reshdr, sizeof (reshdr), 1);
   write_res_id (type);
@@ -405,8 +408,8 @@ write_res_data (data, size, count)
      size_t size;
      int count;
 {
-  if (fwrite (data, size, count, fres) != count)
-    fatal ("%s: %s: could not write to file", program_name, filename);
+  if (fwrite (data, size, count, fres) != (size_t) count)
+    fatal ("%s: could not write to file", filename);
 }
 
 /* Read data from file, abort on failure */
@@ -416,8 +419,8 @@ read_res_data (data, size, count)
      size_t size;
      int count;
 {
-  if (fread (data, size, count, fres) != count)
-    fatal ("%s: %s: unexpected end of file", program_name, filename);
+  if (fread (data, size, count, fres) != (size_t) count)
+    fatal ("%s: unexpected end of file", filename);
 }
 
 /* Write a resource id */
@@ -454,7 +457,7 @@ write_res_info (info)
 }
 
 /* read a resource identifier */
-void 
+void
 read_res_id (id)
      struct res_id *id;
 {
@@ -489,7 +492,6 @@ read_unistring (len)
   unichar *s;
   unichar c;
   unichar *p;
-  int n;
   int l;
 
   *len = 0;
@@ -513,7 +515,9 @@ read_unistring (len)
 static void
 res_align_file (void)
 {
-  if (fseek (fres, ftell (fres) % 4, SEEK_CUR) != 0)
+  int pos = ftell (fres);
+  int skip = ((pos + 3) & ~3) - pos;
+  if (fseek (fres, skip, SEEK_CUR) != 0)
     fatal ("%s: %s: unable to align file", program_name, filename);
 }