#MODE_READWRITE and read/seek/write on Amiga compatibles
Posted: Thu Nov 29, 2018 6:23 pm
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.
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...
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$))
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...