Loading include/utils/Asset.h +32 −30 Original line number Diff line number Diff line Loading @@ -23,9 +23,11 @@ #include <stdio.h> #include <sys/types.h> #include "FileMap.h" #include "String8.h" #include "Errors.h" #include <utils/Compat.h> #include <utils/Errors.h> #include <utils/FileMap.h> #include <utils/String8.h> namespace android { Loading Loading @@ -69,10 +71,10 @@ public: /* * Seek to the specified offset. "whence" uses the same values as * lseek/fseek. Returns the new position on success, or (off_t) -1 * lseek/fseek. Returns the new position on success, or (off64_t) -1 * on failure. */ virtual off_t seek(off_t offset, int whence) = 0; virtual off64_t seek(off64_t offset, int whence) = 0; /* * Close the asset, freeing all associated resources. Loading @@ -87,19 +89,19 @@ public: /* * Get the total amount of data that can be read. */ virtual off_t getLength(void) const = 0; virtual off64_t getLength(void) const = 0; /* * Get the total amount of data that can be read from the current position. */ virtual off_t getRemainingLength(void) const = 0; virtual off64_t getRemainingLength(void) const = 0; /* * Open a new file descriptor that can be used to read this asset. * Returns -1 if you can not use the file descriptor (for example if the * asset is compressed). */ virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const = 0; virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const = 0; /* * Return whether this asset's buffer is allocated in RAM (not mmapped). Loading @@ -120,7 +122,7 @@ protected: Asset(void); // constructor; only invoked indirectly /* handle common seek() housekeeping */ off_t handleSeek(off_t offset, int whence, off_t curPosn, off_t maxPosn); off64_t handleSeek(off64_t offset, int whence, off64_t curPosn, off64_t maxPosn); /* set the asset source string */ void setAssetSource(const String8& path) { mAssetSource = path; } Loading Loading @@ -153,7 +155,7 @@ private: * * The asset takes ownership of the file descriptor. */ static Asset* createFromFileSegment(int fd, off_t offset, size_t length, static Asset* createFromFileSegment(int fd, off64_t offset, size_t length, AccessMode mode); /* Loading @@ -166,7 +168,7 @@ private: * This may not verify the validity of the compressed data until first * use. */ static Asset* createFromCompressedData(int fd, off_t offset, static Asset* createFromCompressedData(int fd, off64_t offset, int compressionMethod, size_t compressedLength, size_t uncompressedLength, AccessMode mode); #endif Loading Loading @@ -221,7 +223,7 @@ public: * * On success, the object takes ownership of "fd". */ status_t openChunk(const char* fileName, int fd, off_t offset, size_t length); status_t openChunk(const char* fileName, int fd, off64_t offset, size_t length); /* * Use a memory-mapped region. Loading @@ -234,18 +236,18 @@ public: * Standard Asset interfaces. */ virtual ssize_t read(void* buf, size_t count); virtual off_t seek(off_t offset, int whence); virtual off64_t seek(off64_t offset, int whence); virtual void close(void); virtual const void* getBuffer(bool wordAligned); virtual off_t getLength(void) const { return mLength; } virtual off_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const; virtual off64_t getLength(void) const { return mLength; } virtual off64_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const; virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // absolute file offset of start of chunk off_t mLength; // length of the chunk off_t mOffset; // current local offset, 0 == mStart off64_t mStart; // absolute file offset of start of chunk off64_t mLength; // length of the chunk off64_t mOffset; // current local offset, 0 == mStart FILE* mFp; // for read/seek char* mFileName; // for opening Loading Loading @@ -276,7 +278,7 @@ public: * * On success, the object takes ownership of "fd". */ status_t openChunk(int fd, off_t offset, int compressionMethod, status_t openChunk(int fd, off64_t offset, int compressionMethod, size_t uncompressedLen, size_t compressedLen); /* Loading @@ -291,19 +293,19 @@ public: * Standard Asset interfaces. */ virtual ssize_t read(void* buf, size_t count); virtual off_t seek(off_t offset, int whence); virtual off64_t seek(off64_t offset, int whence); virtual void close(void); virtual const void* getBuffer(bool wordAligned); virtual off_t getLength(void) const { return mUncompressedLen; } virtual off_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const { return -1; } virtual off64_t getLength(void) const { return mUncompressedLen; } virtual off64_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const { return -1; } virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // offset to start of compressed data off_t mCompressedLen; // length of the compressed data off_t mUncompressedLen; // length of the uncompressed data off_t mOffset; // current offset, 0 == start of uncomp data off64_t mStart; // offset to start of compressed data off64_t mCompressedLen; // length of the compressed data off64_t mUncompressedLen; // length of the uncompressed data off64_t mOffset; // current offset, 0 == start of uncomp data FileMap* mMap; // for memory-mapped input int mFd; // for file input Loading include/utils/Compat.h 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __LIB_UTILS_COMPAT_H #define __LIB_UTILS_COMPAT_H #include <unistd.h> /* Compatibility definitions for non-Linux (i.e., BSD-based) hosts. */ #ifndef HAVE_OFF64_T #if _FILE_OFFSET_BITS < 64 #error "_FILE_OFFSET_BITS < 64; large files are not supported on this platform" #endif /* _FILE_OFFSET_BITS < 64 */ typedef off_t off64_t; static inline off64_t lseek64(int fd, off64_t offset, int whence) { return lseek(fd, offset, whence); } #ifdef HAVE_PREAD static inline ssize_t pread64(int fd, void* buf, size_t nbytes, off64_t offset) { return pread(fd, buf, nbytes, offset); } #endif #endif /* !HAVE_OFF64_T */ #endif /* __LIB_UTILS_COMPAT_H */ include/utils/FileMap.h +5 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <sys/types.h> #include <utils/Compat.h> #ifdef HAVE_WIN32_FILEMAP #include <windows.h> #endif Loading Loading @@ -55,7 +57,7 @@ public: * Returns "false" on failure. */ bool create(const char* origFileName, int fd, off_t offset, size_t length, bool readOnly); off64_t offset, size_t length, bool readOnly); /* * Return the name of the file this map came from, if known. Loading @@ -75,7 +77,7 @@ public: /* * Get the data offset used to create this map. */ off_t getDataOffset(void) const { return mDataOffset; } off64_t getDataOffset(void) const { return mDataOffset; } /* * Get a "copy" of the object. Loading Loading @@ -118,7 +120,7 @@ private: char* mFileName; // original file name, if known void* mBasePtr; // base of mmap area; page aligned size_t mBaseLength; // length, measured from "mBasePtr" off_t mDataOffset; // offset used when map was created off64_t mDataOffset; // offset used when map was created void* mDataPtr; // start of requested data, offset from base size_t mDataLength; // length, measured from "mDataPtr" #ifdef HAVE_WIN32_FILEMAP Loading include/utils/StreamingZipInflater.h +6 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <inttypes.h> #include <zlib.h> #include <utils/Compat.h> namespace android { class StreamingZipInflater { Loading @@ -29,7 +31,7 @@ public: static const size_t OUTPUT_CHUNK_SIZE = 64 * 1024; // Flavor that pages in the compressed data from a fd StreamingZipInflater(int fd, off_t compDataStart, size_t uncompSize, size_t compSize); StreamingZipInflater(int fd, off64_t compDataStart, size_t uncompSize, size_t compSize); // Flavor that gets the compressed data from an in-memory buffer StreamingZipInflater(class FileMap* dataMap, size_t uncompSize); Loading @@ -43,7 +45,7 @@ public: // seeking backwards requires uncompressing fom the beginning, so is very // expensive. seeking forwards only requires uncompressing from the current // position to the destination. off_t seekAbsolute(off_t absoluteInputPosition); off64_t seekAbsolute(off64_t absoluteInputPosition); private: void initInflateState(); Loading @@ -51,7 +53,7 @@ private: // where to find the uncompressed data int mFd; off_t mInFileStart; // where the compressed data lives in the file off64_t mInFileStart; // where the compressed data lives in the file class FileMap* mDataMap; z_stream mInflateState; Loading @@ -63,7 +65,7 @@ private: size_t mOutTotalSize; // total uncompressed size of the blob // current output state bookkeeping off_t mOutCurPosition; // current position in total offset off64_t mOutCurPosition; // current position in total offset size_t mOutLastDecoded; // last decoded byte + 1 in mOutbuf size_t mOutDeliverable; // next undelivered byte of decoded output in mOutBuf Loading include/utils/ZipFileCRO.h +3 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ #include <stdlib.h> #include <unistd.h> #include <utils/Compat.h> #ifdef __cplusplus extern "C" { #endif Loading @@ -48,7 +50,7 @@ extern ZipEntryCRO ZipFileCRO_findEntryByName(ZipFileCRO zip, extern bool ZipFileCRO_getEntryInfo(ZipFileCRO zip, ZipEntryCRO entry, int* pMethod, size_t* pUncompLen, size_t* pCompLen, off_t* pOffset, long* pModWhen, long* pCrc32); size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32); extern bool ZipFileCRO_uncompressEntry(ZipFileCRO zip, ZipEntryCRO entry, int fd); Loading Loading
include/utils/Asset.h +32 −30 Original line number Diff line number Diff line Loading @@ -23,9 +23,11 @@ #include <stdio.h> #include <sys/types.h> #include "FileMap.h" #include "String8.h" #include "Errors.h" #include <utils/Compat.h> #include <utils/Errors.h> #include <utils/FileMap.h> #include <utils/String8.h> namespace android { Loading Loading @@ -69,10 +71,10 @@ public: /* * Seek to the specified offset. "whence" uses the same values as * lseek/fseek. Returns the new position on success, or (off_t) -1 * lseek/fseek. Returns the new position on success, or (off64_t) -1 * on failure. */ virtual off_t seek(off_t offset, int whence) = 0; virtual off64_t seek(off64_t offset, int whence) = 0; /* * Close the asset, freeing all associated resources. Loading @@ -87,19 +89,19 @@ public: /* * Get the total amount of data that can be read. */ virtual off_t getLength(void) const = 0; virtual off64_t getLength(void) const = 0; /* * Get the total amount of data that can be read from the current position. */ virtual off_t getRemainingLength(void) const = 0; virtual off64_t getRemainingLength(void) const = 0; /* * Open a new file descriptor that can be used to read this asset. * Returns -1 if you can not use the file descriptor (for example if the * asset is compressed). */ virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const = 0; virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const = 0; /* * Return whether this asset's buffer is allocated in RAM (not mmapped). Loading @@ -120,7 +122,7 @@ protected: Asset(void); // constructor; only invoked indirectly /* handle common seek() housekeeping */ off_t handleSeek(off_t offset, int whence, off_t curPosn, off_t maxPosn); off64_t handleSeek(off64_t offset, int whence, off64_t curPosn, off64_t maxPosn); /* set the asset source string */ void setAssetSource(const String8& path) { mAssetSource = path; } Loading Loading @@ -153,7 +155,7 @@ private: * * The asset takes ownership of the file descriptor. */ static Asset* createFromFileSegment(int fd, off_t offset, size_t length, static Asset* createFromFileSegment(int fd, off64_t offset, size_t length, AccessMode mode); /* Loading @@ -166,7 +168,7 @@ private: * This may not verify the validity of the compressed data until first * use. */ static Asset* createFromCompressedData(int fd, off_t offset, static Asset* createFromCompressedData(int fd, off64_t offset, int compressionMethod, size_t compressedLength, size_t uncompressedLength, AccessMode mode); #endif Loading Loading @@ -221,7 +223,7 @@ public: * * On success, the object takes ownership of "fd". */ status_t openChunk(const char* fileName, int fd, off_t offset, size_t length); status_t openChunk(const char* fileName, int fd, off64_t offset, size_t length); /* * Use a memory-mapped region. Loading @@ -234,18 +236,18 @@ public: * Standard Asset interfaces. */ virtual ssize_t read(void* buf, size_t count); virtual off_t seek(off_t offset, int whence); virtual off64_t seek(off64_t offset, int whence); virtual void close(void); virtual const void* getBuffer(bool wordAligned); virtual off_t getLength(void) const { return mLength; } virtual off_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const; virtual off64_t getLength(void) const { return mLength; } virtual off64_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const; virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // absolute file offset of start of chunk off_t mLength; // length of the chunk off_t mOffset; // current local offset, 0 == mStart off64_t mStart; // absolute file offset of start of chunk off64_t mLength; // length of the chunk off64_t mOffset; // current local offset, 0 == mStart FILE* mFp; // for read/seek char* mFileName; // for opening Loading Loading @@ -276,7 +278,7 @@ public: * * On success, the object takes ownership of "fd". */ status_t openChunk(int fd, off_t offset, int compressionMethod, status_t openChunk(int fd, off64_t offset, int compressionMethod, size_t uncompressedLen, size_t compressedLen); /* Loading @@ -291,19 +293,19 @@ public: * Standard Asset interfaces. */ virtual ssize_t read(void* buf, size_t count); virtual off_t seek(off_t offset, int whence); virtual off64_t seek(off64_t offset, int whence); virtual void close(void); virtual const void* getBuffer(bool wordAligned); virtual off_t getLength(void) const { return mUncompressedLen; } virtual off_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const { return -1; } virtual off64_t getLength(void) const { return mUncompressedLen; } virtual off64_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off64_t* outStart, off64_t* outLength) const { return -1; } virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // offset to start of compressed data off_t mCompressedLen; // length of the compressed data off_t mUncompressedLen; // length of the uncompressed data off_t mOffset; // current offset, 0 == start of uncomp data off64_t mStart; // offset to start of compressed data off64_t mCompressedLen; // length of the compressed data off64_t mUncompressedLen; // length of the uncompressed data off64_t mOffset; // current offset, 0 == start of uncomp data FileMap* mMap; // for memory-mapped input int mFd; // for file input Loading
include/utils/Compat.h 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __LIB_UTILS_COMPAT_H #define __LIB_UTILS_COMPAT_H #include <unistd.h> /* Compatibility definitions for non-Linux (i.e., BSD-based) hosts. */ #ifndef HAVE_OFF64_T #if _FILE_OFFSET_BITS < 64 #error "_FILE_OFFSET_BITS < 64; large files are not supported on this platform" #endif /* _FILE_OFFSET_BITS < 64 */ typedef off_t off64_t; static inline off64_t lseek64(int fd, off64_t offset, int whence) { return lseek(fd, offset, whence); } #ifdef HAVE_PREAD static inline ssize_t pread64(int fd, void* buf, size_t nbytes, off64_t offset) { return pread(fd, buf, nbytes, offset); } #endif #endif /* !HAVE_OFF64_T */ #endif /* __LIB_UTILS_COMPAT_H */
include/utils/FileMap.h +5 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <sys/types.h> #include <utils/Compat.h> #ifdef HAVE_WIN32_FILEMAP #include <windows.h> #endif Loading Loading @@ -55,7 +57,7 @@ public: * Returns "false" on failure. */ bool create(const char* origFileName, int fd, off_t offset, size_t length, bool readOnly); off64_t offset, size_t length, bool readOnly); /* * Return the name of the file this map came from, if known. Loading @@ -75,7 +77,7 @@ public: /* * Get the data offset used to create this map. */ off_t getDataOffset(void) const { return mDataOffset; } off64_t getDataOffset(void) const { return mDataOffset; } /* * Get a "copy" of the object. Loading Loading @@ -118,7 +120,7 @@ private: char* mFileName; // original file name, if known void* mBasePtr; // base of mmap area; page aligned size_t mBaseLength; // length, measured from "mBasePtr" off_t mDataOffset; // offset used when map was created off64_t mDataOffset; // offset used when map was created void* mDataPtr; // start of requested data, offset from base size_t mDataLength; // length, measured from "mDataPtr" #ifdef HAVE_WIN32_FILEMAP Loading
include/utils/StreamingZipInflater.h +6 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <inttypes.h> #include <zlib.h> #include <utils/Compat.h> namespace android { class StreamingZipInflater { Loading @@ -29,7 +31,7 @@ public: static const size_t OUTPUT_CHUNK_SIZE = 64 * 1024; // Flavor that pages in the compressed data from a fd StreamingZipInflater(int fd, off_t compDataStart, size_t uncompSize, size_t compSize); StreamingZipInflater(int fd, off64_t compDataStart, size_t uncompSize, size_t compSize); // Flavor that gets the compressed data from an in-memory buffer StreamingZipInflater(class FileMap* dataMap, size_t uncompSize); Loading @@ -43,7 +45,7 @@ public: // seeking backwards requires uncompressing fom the beginning, so is very // expensive. seeking forwards only requires uncompressing from the current // position to the destination. off_t seekAbsolute(off_t absoluteInputPosition); off64_t seekAbsolute(off64_t absoluteInputPosition); private: void initInflateState(); Loading @@ -51,7 +53,7 @@ private: // where to find the uncompressed data int mFd; off_t mInFileStart; // where the compressed data lives in the file off64_t mInFileStart; // where the compressed data lives in the file class FileMap* mDataMap; z_stream mInflateState; Loading @@ -63,7 +65,7 @@ private: size_t mOutTotalSize; // total uncompressed size of the blob // current output state bookkeeping off_t mOutCurPosition; // current position in total offset off64_t mOutCurPosition; // current position in total offset size_t mOutLastDecoded; // last decoded byte + 1 in mOutbuf size_t mOutDeliverable; // next undelivered byte of decoded output in mOutBuf Loading
include/utils/ZipFileCRO.h +3 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ #include <stdlib.h> #include <unistd.h> #include <utils/Compat.h> #ifdef __cplusplus extern "C" { #endif Loading @@ -48,7 +50,7 @@ extern ZipEntryCRO ZipFileCRO_findEntryByName(ZipFileCRO zip, extern bool ZipFileCRO_getEntryInfo(ZipFileCRO zip, ZipEntryCRO entry, int* pMethod, size_t* pUncompLen, size_t* pCompLen, off_t* pOffset, long* pModWhen, long* pCrc32); size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32); extern bool ZipFileCRO_uncompressEntry(ZipFileCRO zip, ZipEntryCRO entry, int fd); Loading