2007-03-24 Paul Brook <paul@codesourcery.com>
[binutils-gdb.git] / binutils / resres.c
index 6a860eb2aebbec859e2069fd04031d3e718f7f61..1489d5eeda49e1377b1c784e75688dbc0193be0b 100644 (file)
@@ -1,5 +1,5 @@
 /* resres.c: read_res_file and write_res_file implementation for windres.
-   Copyright 1998, 1999 Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
    Written by Anders Norlander <anorland@hem2.passagen.se>.
 
    This file is part of GNU Binutils.
@@ -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.  */
 
 /* FIXME: This file does not work correctly in a cross configuration.
    It assumes that it can use fread and fwrite to read and write
@@ -211,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;
 
@@ -387,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);
@@ -406,7 +408,7 @@ write_res_data (data, size, count)
      size_t size;
      int count;
 {
-  if (fwrite (data, size, count, fres) != (size_t) count)
+  if ((size_t) fwrite (data, size, count, fres) != (size_t) count)
     fatal ("%s: could not write to file", filename);
 }
 
@@ -455,7 +457,7 @@ write_res_info (info)
 }
 
 /* read a resource identifier */
-void 
+void
 read_res_id (id)
      struct res_id *id;
 {
@@ -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);
 }