ssize_t FileSource::readAt(off64_t offset, void *data, size_t size) { if (mFd < 0) { return NO_INIT; } Mutex::Autolock autoLock(mLock); if (mLength >= 0) { if (offset >= mLength) { return 0; // read beyond EOF. } uint64_t numAvailable = mLength - offset; if ((uint64_t)size > numAvailable) { size = numAvailable; } } if (mDecryptHandle != NULL && DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) { return readAtDRM(offset, data, size); } else { off64_t result = lseek64(mFd, offset + mOffset, SEEK_SET); if (result == -1) { ALOGE("seek to %lld failed", (long long)(offset + mOffset)); return UNKNOWN_ERROR; } return ::read(mFd, data, size); } }
ssize_t FileSource::readAt(off_t offset, void *data, size_t size) { if (mFile == NULL) { return NO_INIT; } Mutex::Autolock autoLock(mLock); if (mLength >= 0) { if (offset >= mLength) { return 0; // read beyond EOF. } int64_t numAvailable = mLength - offset; if ((int64_t)size > numAvailable) { size = numAvailable; } } if (mDecryptHandle != NULL && DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) { return readAtDRM(offset, data, size); } else { int err = fseeko(mFile, offset + mOffset, SEEK_SET); if (err < 0) { LOGE("seek to %lld failed", offset + mOffset); return UNKNOWN_ERROR; } return fread(data, 1, size, mFile); } }