#MODE_READWRITE and read/seek/write on Amiga compatibles

Report any Hollywood bugs here
Post Reply
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

#MODE_READWRITE and read/seek/write on Amiga compatibles

Post by jPV »

It seems there's something wrong when you try to seek&write after reading from a file. If you don't read first, then seeking and writing works. This happens on MorphOS, OS3, and OS4, but not on Windows.

Code: Select all

f$="ram:test.txt"

; This writes to the middle of the file as supposed
StringToFile("abcdefg", f$)
f=OpenFile(Nil, f$, #MODE_READWRITE)
Seek(f, 3)
WriteString(f, "0")
CloseFile(f)
DebugPrint(FileToString(f$))

; Why this appends to the end and doesn't write to the middle of the file?
StringToFile("abcdefg", f$)
f=OpenFile(Nil, f$, #MODE_READWRITE)
ReadString(f, 1)
Seek(f, 3)
WriteString(f, "0")
CloseFile(f)
DebugPrint(FileToString(f$))   
The output from this under Amiga platforms is:
abc0efg 7
abcdefg0 8

While on Windows it is:
abc0efg 7
abc0efg 7

I tried to replicate this on plain Lua on MorphOS, and there it prints just like on Windows, so it seems it's Hollywood which doesn't do it right for some reason.

A workaround for this is to open a file, read it and store information you need, close file, re-open it and write then what you need...
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #MODE_READWRITE and read/seek/write on Amiga compatibles

Post by airsoftsoftwair »

Interesting observation. I'll see what's wrong there.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: #MODE_READWRITE and read/seek/write on Amiga compatibles

Post by airsoftsoftwair »

Fixed, thanks for reporting. The problem is that Hollywood uses its own file buffering mechanism because the buffered I/O functions found in dos.library in OS3, OS4, AROS and MorphOS are very slow. But of course custom file buffering can get a little tricky so I'm glad you spotted this problem :)

Code: Select all

 
 - Fix [Amiga]: Fixed wrong file cursor positioning when writing to a file after seeking it to a
   position that didn't require a physical seek because the new position was still within the file's
   internal read buffer kept by Hollywood
Post Reply