mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
fsdev: add way of getting last returned result. (#276)
Adds fsdevGetLastResult, which returns a thread local Result updated by every call to fsdev_translate_error. Also changes fsdev_translate_error to return EIO instead of raw results, when not translatable.
This commit is contained in:
parent
e359010e75
commit
e114a361be
@ -53,3 +53,6 @@ Result fsdevDeleteDirectoryRecursively(const char *path);
|
||||
|
||||
/// Unmounts all devices and cleans up any resources used by the FS driver.
|
||||
Result fsdevUnmountAll(void);
|
||||
|
||||
/// Retrieves the last native result code generated during a failed fsdev operation.
|
||||
Result fsdevGetLastResult(void);
|
||||
|
@ -101,6 +101,7 @@ typedef struct
|
||||
static bool fsdev_initialised = false;
|
||||
static s32 fsdev_fsdevice_default = -1;
|
||||
static s32 fsdev_fsdevice_cwd = -1;
|
||||
static __thread Result fsdev_last_result = 0;
|
||||
static fsdev_fsdevice fsdev_fsdevices[32];
|
||||
|
||||
/*! @endcond */
|
||||
@ -1647,6 +1648,7 @@ error_cmp(const void *p1, const void *p2)
|
||||
static int
|
||||
fsdev_translate_error(Result error)
|
||||
{
|
||||
fsdev_last_result = error;
|
||||
error_map_t key = { .fs_error = error };
|
||||
const error_map_t *rc = bsearch(&key, error_table, num_errors,
|
||||
sizeof(error_map_t), error_cmp);
|
||||
@ -1654,6 +1656,14 @@ fsdev_translate_error(Result error)
|
||||
if(rc != NULL)
|
||||
return rc->error;
|
||||
|
||||
return (int)error;
|
||||
return EIO;
|
||||
}
|
||||
|
||||
/*! Getter for last error code translated to errno by fsdev library.
|
||||
*
|
||||
* @returns result
|
||||
*/
|
||||
Result fsdevGetLastResult(void) {
|
||||
return fsdev_last_result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user