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:
Henrik Rydgard 2014-06-10 01:00:34 +02:00
parent 120e4329ba
commit 0b42530fd8
2 changed files with 38 additions and 1 deletions

View File

@ -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

View File

@ -62,6 +62,9 @@ public:
u32 GetNumBlocks() {return (u32)(filesize / GetBlockSize());}
private:
#ifdef ANDROID
int fd;
#endif
FILE *f;
u64 filesize;
};