WiiFlow_Lite/source/loader/fs.c
fix94.1 0fc21f82a3 -big code cleanup, removed all those SAFE_ and SMART_
thingys and replaced it with their proper calls
-fixed some big memory bugs, downloading much covers shouldn't
be a problem anymore, also memory management should work better
-fixed typo in debug print on game boot, also changed some
things in apploader, making it ready to remove linker script
properly, still in but I hope not for long ;)
-modified wiiflow startup and init order a bit
2012-05-13 15:13:33 +00:00

45 lines
775 B
C

#include <ogcsys.h>
#include <locale.h>
#include <ogc/isfs.h>
#include <malloc.h>
#include "utils.h"
#include "mem2.hpp"
#include "fs.h"
u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length)
{
*size = 0;
s32 fd = ISFS_Open((const char *) path, ISFS_OPEN_READ);
u8 *buf = NULL;
static fstats stats ATTRIBUTE_ALIGN(32);
if (fd >= 0)
{
if (ISFS_GetFileStats(fd, &stats) >= 0)
{
if (length <= 0) length = stats.file_length;
if (length > 0)
buf = (u8 *) MEM2_alloc(ALIGN32(length));
if (buf)
{
*size = stats.file_length;
if (ISFS_Read(fd, (char*)buf, length) != length)
{
*size = 0;
free(buf);
}
}
}
ISFS_Close(fd);
}
if (*size > 0)
{
DCFlushRange(buf, *size);
ICInvalidateRange(buf, *size);
}
return buf;
}