Patch: Initialise new file space to zero for Beos
Nick Clifton
nickc@cygnus.com
Sat Sep 18 02:43:00 GMT 1999
Hi Guys,
Does anyone have any objections to my applying the following patch ?
It enhances bfd_seek() so that, for BeOS only, any newly created
file space is initialised to zero. The BeOS fseek function does not
do this automatically (unlike fseek on other OSes), and as a result
binary comparisons of identical files fail. This means that
bootstrapping under BeOS does not work.
Cheers
Nick
1999-09-18 Nick Clifton <nickc@cygnus.com>
* libbfd.c (bfd_seek): For BeOS, write zeros into extended
file space. Patch developed with Fred Fish.
Index: libbfd.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/libbfd.c,v
retrieving revision 1.6
diff -p -r1.6 libbfd.c
*** libbfd.c 1999/09/12 14:27:21 1.6
--- libbfd.c 1999/09/18 09:38:57
*************** bfd_seek (abfd, position, direction)
*** 723,728 ****
--- 723,774 ----
if (direction == SEEK_SET && abfd->my_archive != NULL)
file_position += abfd->origin;
+ #if defined __BEOS__
+ {
+ file_ptr eof;
+ file_ptr pos;
+
+ pos = ftell (f);
+ fseek (f, 0L, SEEK_END);
+ eof = ftell (f);
+
+ if (direction == SEEK_CUR)
+ {
+ direction = SEEK_SET;
+ file_position += pos;
+ }
+
+ /* When extending a file beyond its original length the fseek() function
+ under BeOS does not initialise the new space to zero. This means that
+ random garbage can be picked up, which in turn means that two identical
+ files assembled and linked in the same way can nevertheless still fail
+ a binary compare. We fix this here by explicitly initialising the
+ extra space. */
+ if (eof < file_position)
+ {
+ file_ptr diff;
+ static char zeros[512];
+
+ diff = file_position - eof;
+
+ while (diff >= sizeof (zeros))
+ {
+ fwrite (zeros, sizeof (zeros), 1, f);
+ diff -= sizeof (zeros);
+ }
+
+ if (diff > 0)
+ fwrite (zeros, diff, 1, f);
+
+ /* In theory we do not need to perform the fseek now, since the fwrite
+ calls will have moved the file pointer to the correct location. In
+ practice however we leave the call in, just in case something went
+ wrong with the fwrites and we missed it. (After all we are not
+ checking their return codes). */
+ }
+ }
+ #endif
+
result = fseek (f, file_position, direction);
if (result != 0)
More information about the Binutils
mailing list