diff --git a/native/android/asset_manager.cpp b/native/android/asset_manager.cpp index 33f088d96c02d..f5db57c1ff85a 100644 --- a/native/android/asset_manager.cpp +++ b/native/android/asset_manager.cpp @@ -178,6 +178,11 @@ off_t AAsset_seek(AAsset* asset, off_t offset, int whence) return asset->mAsset->seek(offset, whence); } +off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence) +{ + return asset->mAsset->seek(offset, whence); +} + void AAsset_close(AAsset* asset) { asset->mAsset->close(); @@ -194,14 +199,35 @@ off_t AAsset_getLength(AAsset* asset) return asset->mAsset->getLength(); } +off64_t AAsset_getLength64(AAsset* asset) +{ + return asset->mAsset->getLength(); +} + off_t AAsset_getRemainingLength(AAsset* asset) { return asset->mAsset->getRemainingLength(); } +off64_t AAsset_getRemainingLength64(AAsset* asset) +{ + return asset->mAsset->getRemainingLength(); +} + int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength) { - return asset->mAsset->openFileDescriptor((off64_t*)outStart, (off64_t*)outLength); + off64_t outStart64, outLength64; + + int ret = asset->mAsset->openFileDescriptor(&outStart64, &outLength64); + + *outStart = off_t(outStart64); + *outLength = off_t(outLength64); + return ret; +} + +int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength) +{ + return asset->mAsset->openFileDescriptor(outStart, outLength); } int AAsset_isAllocated(AAsset* asset) diff --git a/native/include/android/asset_manager.h b/native/include/android/asset_manager.h index 4fa0ef3a3a122..f5df46bd74835 100644 --- a/native/include/android/asset_manager.h +++ b/native/include/android/asset_manager.h @@ -93,6 +93,17 @@ int AAsset_read(AAsset* asset, void* buf, size_t count); */ off_t AAsset_seek(AAsset* asset, off_t offset, int whence); +/** + * Seek to the specified offset within the asset data. 'whence' uses the + * same constants as lseek()/fseek(). + * + * Uses 64-bit data type for large files as opposed to the 32-bit type used + * by AAsset_seek. + * + * Returns the new position on success, or (off64_t) -1 on error. + */ +off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence); + /** * Close the asset, freeing all associated resources. */ @@ -110,19 +121,45 @@ const void* AAsset_getBuffer(AAsset* asset); */ off_t AAsset_getLength(AAsset* asset); +/** + * Report the total size of the asset data. Reports the size using a 64-bit + * number insted of 32-bit as AAsset_getLength. + */ +off64_t AAsset_getLength64(AAsset* asset); + /** * Report the total amount of asset data that can be read from the current position. */ off_t AAsset_getRemainingLength(AAsset* asset); /** - * Open a new file descriptor that can be used to read the asset data. + * Report the total amount of asset data that can be read from the current position. + * + * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does. + */ +off64_t AAsset_getRemainingLength64(AAsset* asset); + +/** + * Open a new file descriptor that can be used to read the asset data. If the + * start or length cannot be represented by a 32-bit number, it will be + * truncated. If the file is large, use AAsset_openFileDescriptor64 instead. * * Returns < 0 if direct fd access is not possible (for example, if the asset is * compressed). */ int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); +/** + * Open a new file descriptor that can be used to read the asset data. + * + * Uses a 64-bit number for the offset and length instead of 32-bit instead of + * as AAsset_openFileDescriptor does. + * + * Returns < 0 if direct fd access is not possible (for example, if the asset is + * compressed). + */ +int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength); + /** * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not * mmapped).