mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-13 21:51:53 +01:00
43 lines
1013 B
C
43 lines
1013 B
C
|
#include "devoptab_fs.h"
|
||
|
|
||
|
int
|
||
|
__wut_fs_stat(struct _reent *r,
|
||
|
const char *file,
|
||
|
struct stat *st)
|
||
|
{
|
||
|
int fd;
|
||
|
FSStatus rc;
|
||
|
|
||
|
if (file == NULL) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// Set up command block
|
||
|
FSCmdBlock fsCmd;
|
||
|
FSInitCmdBlock(&fsCmd);
|
||
|
|
||
|
// First try open as file
|
||
|
rc = FSOpenFile(__wut_devoptab_fs_client, &fsCmd, file, "r", (FSFileHandle*)&fd, -1);
|
||
|
|
||
|
if (rc >= 0) {
|
||
|
__wut_fs_file_t tmpfd = { .fd = fd };
|
||
|
rc = __wut_fs_fstat(r, &tmpfd, st);
|
||
|
FSCloseFile(__wut_devoptab_fs_client, &fsCmd, fd, -1);
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
// File failed, so lets try open as directory
|
||
|
rc = FSOpenDir(__wut_devoptab_fs_client, &fsCmd, file, (FSDirectoryHandle*)&fd, -1);
|
||
|
|
||
|
if (rc >= 0) {
|
||
|
memset(st, 0, sizeof(struct stat));
|
||
|
st->st_nlink = 1;
|
||
|
st->st_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
|
||
|
FSCloseDir(__wut_devoptab_fs_client, &fsCmd, fd, -1);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
r->_errno = __wut_fs_translate_error(rc);
|
||
|
return -1;
|
||
|
}
|