Page 1 of 1

StrFile() doesn't seem to allow writing a string to the very beginning of a file

Posted: Sun Aug 02, 2020 1:10 pm
by HGAutomator
Hi,

If we call StrFile as

Code: Select all

STRFILE( "Initial Bytes", "File.dat", .T., 0 )
, then the string


Initial Bytes


is written to the end of the file.

If you write

Code: Select all

STRFILE( "Initial Bytes", "File.dat", .T., 1 )


, then the string is written properly beginning with the second byte (byte 1).

But there doesn't seem to be any way to write a string starting with the first byte (byte 0).

Re: StrFile() doesn't seem to allow writing a string to the very beginning of a file

Posted: Sun Aug 02, 2020 2:53 pm
by srvet_claudio
Hi,
if you are right it is an error in the source code (C:\harbour-core-master\contrib\hbct\ctstrfil.c):

Code: Select all

if( nOffset )
   hb_fsSeekLarge( hFile, nOffset, FS_SET );
the correct way would be:

Code: Select all

if( nOffset >= 0 )
   hb_fsSeekLarge( hFile, nOffset, FS_SET );
when the nOffset is zero the function write to the end of the file.

Re: StrFile() doesn't seem to allow writing a string to the very beginning of a file

Posted: Sun Aug 02, 2020 3:09 pm
by HGAutomator
Ok, thanks. I'll do it a different way.


Regards,


srvet_claudio wrote: Sun Aug 02, 2020 2:53 pm Hi,
if you are right it is an error in the source code (C:\harbour-core-master\contrib\hbct\ctstrfil.c):

Code: Select all

if( nOffset )
   hb_fsSeekLarge( hFile, nOffset, FS_SET );
the correct way would be:

Code: Select all

if( nOffset >= 0 )
   hb_fsSeekLarge( hFile, nOffset, FS_SET );
when the nOffset is zero the function write to the end of the file.