1.2.7.4.16 SYS_FS_FileError Function

C

SYS_FS_ERROR SYS_FS_FileError
(
    SYS_FS_HANDLE handle
);

Summary

Returns the file specific error.

Description

For file system functions which accepts valid handle, any error happening in those functions could be retrieved with SYS_FS_FileError. This function returns errors which are file specific.

Please note that if an invalid handle is passed to a file system function, in such a case, SYS_FS_FileError will not return the correct type of error, as the handle was invalid. Therefore, it would be prudent to check the errors using the SYS_FS_Error function.

Precondition

This function has to be called immediately after a failure is observed while doing a file operation. Any subsequent failure will overwrite the cause of previous failure.

Parameters

ParamDescription
handleA valid file handle

Returns

Error code of type SYS_FS_ERROR.

Example

...
SYS_FS_HANDLE fileHandle;
const char *buf = "Hello World";
size_t nbytes;
size_t bytes_written;

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

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

// Write data to the file
bytes_written = SYS_FS_FileWrite(fileHandle, (const void *)buf, nbytes);

if(bytes_written == -1)
{
    // error while writing file
    // find the type (reason) of error
    err = SYS_FS_FileError(fd);
}

Remarks

None.