File write functions not returning bytes actually written
File write functions not returning bytes actually written
WriteByte
WriteCharacter
WriteData
WriteDouble
WriteFloat
WriteLong
WriteQuad
WriteString
WriteStringN
WriteWord
The return values aren't described in the docs but I assume that they indicate bytes actually written.
All the above functions indicate bytes written to a file even when they are not (e.g., full drive).
WriteCharacter
WriteData
WriteDouble
WriteFloat
WriteLong
WriteQuad
WriteString
WriteStringN
WriteWord
The return values aren't described in the docs but I assume that they indicate bytes actually written.
All the above functions indicate bytes written to a file even when they are not (e.g., full drive).
Actually the returnvalues have no meaning at all (thats why there is nothing in the help about them)
Since the file operations are buffered in memory, it cannot be known wether a write
to disk will succeed for this particular operation.
Checking the free disk space for each file operation would be a huge slowdown
and defeat the whole purpose of the buffering.
I would suggest to simply write the whole file and check at the end if the actual
filesize matches what you tried to write. For very large files, a check of the free
disk space inbetween might make sense as well.
Since the file operations are buffered in memory, it cannot be known wether a write
to disk will succeed for this particular operation.
Checking the free disk space for each file operation would be a huge slowdown
and defeat the whole purpose of the buffering.
I would suggest to simply write the whole file and check at the end if the actual
filesize matches what you tried to write. For very large files, a check of the free
disk space inbetween might make sense as well.
quidquid Latine dictum sit altum videtur
> I would suggest to simply write the whole file and check at the end if the
> actual filesize matches what you tried to write
I posted an example of this technique way back in 2004:
http://www.purebasic.fr/english/viewtopic.php?t=11902
> actual filesize matches what you tried to write
I posted an example of this technique way back in 2004:
http://www.purebasic.fr/english/viewtopic.php?t=11902
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
If you are encountering full disk or bad sector or whatever probs, perhaps something like this from time to time (and assuming the file write action has extended the file) -
Not sure if buffering skews this, though. If so, then perhaps flushbuffer first? You probably wouldn't want to do this every write, just from time to time.
Edit:
Lol, that is exactly what your code does, PB! I should have read your link first!

Code: Select all
WriteStringN(1,"ABCDEF") ; or whatever write
If Lof(1) <> Loc(1)
debug "Ah cr@p"
EndIf
Edit:
Lol, that is exactly what your code does, PB! I should have read your link first!

Dare2 cut down to size
@freak
Any chance of changing the behavior of the write functions so that they return #False if writing failed for some reason? and #True if it succeeded?
Win32 API
No idea on Linux or Mac but I assume it's very similar?
Any chance of changing the behavior of the write functions so that they return #False if writing failed for some reason? and #True if it succeeded?
Win32 API
I assume WriteFile() is what PureBasic uses on i.e. Windows, so merely passing along the return vals on writes would be very easy I hope.WriteFile()
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
No idea on Linux or Mac but I assume it's very similar?