mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-12 20:40:49 +00:00
Use low-level I/O on Android for 64-bit offset support
Fixes videos in FF Type-0 on Android. See #6268
This commit is contained in:
parent
120e4329ba
commit
0b42530fd8
@ -44,6 +44,38 @@ BlockDevice *constructBlockDevice(const char *filename) {
|
||||
return new FileBlockDevice(f);
|
||||
}
|
||||
|
||||
|
||||
// Android NDK does not support 64-bit file I/O using C streams
|
||||
// so we fall back onto syscalls
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
FileBlockDevice::FileBlockDevice(FILE *file)
|
||||
: f(file)
|
||||
{
|
||||
fd = fileno(file);
|
||||
|
||||
off64_t off = lseek64(fd, 0, SEEK_END);
|
||||
filesize = off;
|
||||
lseek64(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
FileBlockDevice::~FileBlockDevice()
|
||||
{
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
bool FileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr)
|
||||
{
|
||||
lseek64(fd, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET);
|
||||
if (read(fd, outPtr, 2048) != 2048) {
|
||||
ERROR_LOG(FILESYS, "Could not read() 2048 bytes from block");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FileBlockDevice::FileBlockDevice(FILE *file)
|
||||
: f(file)
|
||||
{
|
||||
@ -59,13 +91,15 @@ FileBlockDevice::~FileBlockDevice()
|
||||
|
||||
bool FileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr)
|
||||
{
|
||||
fseeko(f, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET);
|
||||
fseek(f, (u64)blockNumber * (u64)GetBlockSize(), SEEK_SET);
|
||||
if (fread(outPtr, 1, 2048, f) != 2048)
|
||||
DEBUG_LOG(FILESYS, "Could not read 2048 bytes from block");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// .CSO format
|
||||
|
||||
// compressed ISO(9660) header format
|
||||
|
@ -62,6 +62,9 @@ public:
|
||||
u32 GetNumBlocks() {return (u32)(filesize / GetBlockSize());}
|
||||
|
||||
private:
|
||||
#ifdef ANDROID
|
||||
int fd;
|
||||
#endif
|
||||
FILE *f;
|
||||
u64 filesize;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user