2018-07-19 08:42:12 +01:00
|
|
|
#include "devoptab_fs.h"
|
2018-05-27 12:11:45 +01:00
|
|
|
|
|
|
|
char *
|
|
|
|
__wut_fs_fixpath(struct _reent *r,
|
|
|
|
const char *path)
|
|
|
|
{
|
2018-10-06 10:41:24 +01:00
|
|
|
char *p;
|
|
|
|
char *fixedPath;
|
2018-05-27 12:11:45 +01:00
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
if (!path) {
|
|
|
|
r->_errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = strchr(path, ':') + 1;
|
2018-06-13 17:36:12 +01:00
|
|
|
if (!strchr(path, ':')) {
|
2018-05-27 12:11:45 +01:00
|
|
|
p = (char*)path;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(p) > PATH_MAX) {
|
|
|
|
r->_errno = ENAMETOOLONG;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-06 10:41:24 +01:00
|
|
|
fixedPath = memalign(0x40, PATH_MAX + 1);
|
|
|
|
if (!fixedPath) {
|
|
|
|
r->_errno = ENOMEM;
|
2018-05-27 12:11:45 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-13 17:36:12 +01:00
|
|
|
// cwd is handled by coreinit, so just strip the 'device:' if it exists
|
2018-10-06 10:41:24 +01:00
|
|
|
strcpy(fixedPath, p);
|
|
|
|
return fixedPath;
|
2018-05-27 12:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
__wut_fs_translate_error(FSStatus error)
|
|
|
|
{
|
2018-10-06 10:50:32 +01:00
|
|
|
switch ((int32_t)error) {
|
2018-10-06 10:41:24 +01:00
|
|
|
case FS_STATUS_END:
|
|
|
|
return ENOENT;
|
2018-05-27 12:11:45 +01:00
|
|
|
case FS_STATUS_CANCELLED:
|
|
|
|
return EINVAL;
|
|
|
|
case FS_STATUS_EXISTS:
|
|
|
|
return EEXIST;
|
|
|
|
case FS_STATUS_NOT_FOUND:
|
|
|
|
return ENOENT;
|
|
|
|
case FS_STATUS_STORAGE_FULL:
|
|
|
|
return ENOSPC;
|
|
|
|
case FS_ERROR_INVALID_PATH:
|
|
|
|
return ENAMETOOLONG;
|
|
|
|
default:
|
|
|
|
return (int)error;
|
|
|
|
}
|
|
|
|
}
|