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

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
HGAutomator
Posts: 31
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF
Been thanked: 4 times

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

Post 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).

User avatar
srvet_claudio
Posts: 2111
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 48 times
Been thanked: 223 times
Contact:

Post 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.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

HGAutomator
Posts: 31
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF
Been thanked: 4 times

Post 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.

Post Reply