1.2.7.4.10 SYS_FS_FileSeek Function

C

int32_t SYS_FS_FileSeek
(
    SYS_FS_HANDLE handle,
    int32_t offset,
    SYS_FS_FILE_SEEK_CONTROL whence
);

Summary

Moves the file pointer by the requested offset.

Description

This function sets the file pointer for a open file associated with the file handle, as follows:

  • whence = SYS_FS_SEEK_SET - File offset is set to offset bytes from the beginning.

  • whence = SYS_FS_SEEK_CUR - File offset is set to its current location plus offset.

  • whence = SYS_FS_SEEK_END - File offset is set to the size of the file plus offset. The offset specified for this option should be negative for the file pointer to be valid.

Trying to move the file pointer using SYS_FS_FileSeek, beyond the range of file will only cause the pointer to be moved to the last location of the file.

Precondition

A valid file handle must be obtained before seeking a file.

Parameters

ParamDescription
handleA valid file handle obtained during file open.
offsetThe number of bytes which act as file offset. This value could be a positive or negative value.
whenceType of File Seek operation as specified in SYS_FS_FILE_SEEK_CONTROL.

Returns

On success - The number of bytes by which file pointer is moved (0 or positive number)

On Failure - (-1) If the chosen offset value was (-1), the success or failure can be determined with SYS_FS_Error.

Example

SYS_FS_HANDLE fileHandle;
int status;

fileHandle = SYS_FS_FileOpen("/mnt/myDrive/FILE.txt", (SYS_FS_FILE_OPEN_READ));

if(fileHandle != SYS_FS_HANDLE_INVALID)
{
    // File open is successful
}
...
...

status = SYS_FS_FileSeek(fileHandle, 5, SYS_FS_SEEK_CUR);

if((status != -1) && (status == 5))
{
    // Success
}

Remarks

None.