file_seek
host callCapy
function file_seek(handle : u64, offset : s64, whence : s64) s64
Description
file_seek sets the position for file reads and writes.
Only the three documented whence values are valid. Other values return -1 without changing the position, even when their low bits match a valid value. An invalid resulting offset also returns -1.
Parameters
handle : handle from file_open
offset : byte offset
whence : 0 for the start, 1 for the current position, or 2 for the end
Return Values
The new byte offset. Returns -1 on error.
Example
Capy
var handle := file_open("/tmp/doc-seek.txt", "w")
file_write(handle, "hello world")
file_close(handle)
handle = file_open("/tmp/doc-seek.txt", "r")
file_seek(handle, 6, 0)
print(file_read(handle, 5), "\n")
file_close(handle)
Output
world