WiiFlow_Lite/source/loader/fs.c

49 lines
825 B
C
Raw Normal View History

2012-01-21 21:57:41 +01:00
#include <ogcsys.h>
#include <locale.h>
#include <ogc/isfs.h>
#include <string.h>
2012-01-21 21:57:41 +01:00
#include "fs.h"
#include "utils.h"
#include "memory/mem2.hpp"
static fstats stats ATTRIBUTE_ALIGN(32);
2012-01-21 21:57:41 +01:00
u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length)
{
*size = 0;
s32 fd = ISFS_Open((const char *)path, ISFS_OPEN_READ);
2012-01-21 21:57:41 +01:00
u8 *buf = NULL;
if(fd >= 0)
2012-01-21 21:57:41 +01:00
{
memset(&stats, 0, sizeof(fstats));
if(ISFS_GetFileStats(fd, &stats) >= 0)
2012-01-21 21:57:41 +01:00
{
if(length <= 0)
length = stats.file_length;
if(length > 0)
buf = (u8 *)MEM2_memalign(32, ALIGN32(length));
if(buf)
2012-01-21 21:57:41 +01:00
{
*size = stats.file_length;
if(ISFS_Read(fd, (char*)buf, length) != length)
2012-01-21 21:57:41 +01:00
{
*size = 0;
MEM2_free(buf);
2012-01-21 21:57:41 +01:00
}
}
}
ISFS_Close(fd);
}
if(*size > 0)
2012-01-21 21:57:41 +01:00
{
DCFlushRange(buf, *size);
ICInvalidateRange(buf, *size);
}
return buf;
2012-05-13 19:25:26 +02:00
}