本文整理汇总了C++中FileMap::release方法的典型用法代码示例。如果您正苦于以下问题:C++ FileMap::release方法的具体用法?C++ FileMap::release怎么用?C++ FileMap::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileMap
的用法示例。
在下文中一共展示了FileMap::release方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strerror
FileMap*
FileMapBuffer::createMap(const char* filename)
{
int fd;
size_t length;
fd = ::open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
LOGW("Unable to open file '%s': %s\n", filename, strerror(errno));
return NULL;
}
length = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
FileMap* map = new FileMap();
if (!map) {
LOGW("Unable to create file map for '%s': %s\n", filename, strerror(errno));
return NULL;
}
if (!map->create(filename, fd, 0, length, true)) {
map->release();
LOGW("Unable to create file map for '%s': %s\n", filename, strerror(errno));
return NULL;
}
close(fd);
return map;
}
示例2: open
status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
*outTokenizer = NULL;
int result = NO_ERROR;
int fd = ::open(filename.string(), O_RDONLY);
if (fd < 0) {
result = -errno;
LOGE("Error opening file '%s', %s.", filename.string(), strerror(errno));
} else {
struct stat stat;
if (fstat(fd, &stat)) {
result = -errno;
LOGE("Error getting size of file '%s', %s.", filename.string(), strerror(errno));
} else {
size_t length = size_t(stat.st_size);
FileMap* fileMap = new FileMap();
char* buffer;
if (fileMap->create(NULL, fd, 0, length, true)) {
fileMap->advise(FileMap::SEQUENTIAL);
buffer = static_cast<char*>(fileMap->getDataPtr());
} else {
fileMap->release();
fileMap = NULL;
// Fall back to reading into a buffer since we can't mmap files in sysfs.
// The length we obtained from stat is wrong too (it will always be 4096)
// so we must trust that read will read the entire file.
buffer = new char[length];
ssize_t nrd = read(fd, buffer, length);
if (nrd < 0) {
result = -errno;
LOGE("Error reading file '%s', %s.", filename.string(), strerror(errno));
delete[] buffer;
buffer = NULL;
} else {
length = size_t(nrd);
}
}
if (!result) {
*outTokenizer = new Tokenizer(filename, fileMap, buffer, length);
}
}
close(fd);
}
return result;
}
示例3: readFile
bool BootAnimation::readFile(const char* name, String8& outString)
{
ZipEntryRO entry = mZip->findEntryByName(name);
ALOGE_IF(!entry, "couldn't find %s", name);
if (!entry) {
return false;
}
FileMap* entryMap = mZip->createEntryFileMap(entry);
mZip->releaseEntry(entry);
ALOGE_IF(!entryMap, "entryMap is null");
if (!entryMap) {
return false;
}
outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
entryMap->release();
return true;
}
示例4: createEntryFileMap
/*
* Create a new FileMap object that spans the data in "entry".
*/
FileMap* ZipFileRO::createEntryFileMap(ZipEntryRO entry) const
{
const _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
const ZipEntry& ze = zipEntry->entry;
int fd = GetFileDescriptor(mHandle);
size_t actualLen = 0;
if (ze.method == kCompressStored) {
actualLen = ze.uncompressed_length;
} else {
actualLen = ze.compressed_length;
}
FileMap* newMap = new FileMap();
if (!newMap->create(mFileName, fd, ze.offset, actualLen, true)) {
newMap->release();
return NULL;
}
return newMap;
}
示例5: movie
bool BootAnimation::movie()
{
ZipEntryRO desc = mZip->findEntryByName("desc.txt");
ALOGE_IF(!desc, "couldn't find desc.txt");
if (!desc) {
return false;
}
FileMap* descMap = mZip->createEntryFileMap(desc);
mZip->releaseEntry(desc);
ALOGE_IF(!descMap, "descMap is null");
if (!descMap) {
return false;
}
String8 desString((char const*)descMap->getDataPtr(),
descMap->getDataLength());
descMap->release();
char const* s = desString.string();
Animation animation;
// Parse the description file
for (;;) {
const char* endl = strstr(s, "\n");
if (!endl) break;
String8 line(s, endl - s);
const char* l = line.string();
int fps, width, height, count, pause;
char path[ANIM_ENTRY_NAME_MAX];
char pathType;
if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
//LOGD("> w=%d, h=%d, fps=%d", width, height, fps);
animation.width = width;
animation.height = height;
animation.fps = fps;
}
else if (sscanf(l, " %c %d %d %s", &pathType, &count, &pause, path) == 4) {
//LOGD("> type=%c, count=%d, pause=%d, path=%s", pathType, count, pause, path);
Animation::Part part;
part.playUntilComplete = pathType == 'c';
part.count = count;
part.pause = pause;
part.path = path;
animation.parts.add(part);
}
s = ++endl;
}
// read all the data structures
const size_t pcount = animation.parts.size();
void *cookie = NULL;
if (!mZip->startIteration(&cookie)) {
return false;
}
ZipEntryRO entry;
char name[ANIM_ENTRY_NAME_MAX];
while ((entry = mZip->nextEntry(cookie)) != NULL) {
const int foundEntryName = mZip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
ALOGE("Error fetching entry file name");
continue;
}
const String8 entryName(name);
const String8 path(entryName.getPathDir());
const String8 leaf(entryName.getPathLeaf());
if (leaf.size() > 0) {
for (size_t j=0 ; j<pcount ; j++) {
if (path == animation.parts[j].path) {
int method;
// supports only stored png files
if (mZip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) {
if (method == ZipFileRO::kCompressStored) {
FileMap* map = mZip->createEntryFileMap(entry);
if (map) {
Animation::Frame frame;
frame.name = leaf;
frame.map = map;
Animation::Part& part(animation.parts.editItemAt(j));
part.frames.add(frame);
}
}
}
}
}
}
}
mZip->endIteration(cookie);
// clear screen
glShadeModel(GL_FLAT);
glDisable(GL_DITHER);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
//.........这里部分代码省略.........
示例6: getBuffer
/*
* Return a read-only pointer to a buffer.
*
* We can either read the whole thing in or map the relevant piece of
* the source file. Ideally a map would be established at a higher
* level and we'd be using a different object, but we didn't, so we
* deal with it here.
*/
const void* _FileAsset::getBuffer(bool wordAligned)
{
/* subsequent requests just use what we did previously */
if (mBuf != NULL)
return mBuf;
if (mMap != NULL) {
if (!wordAligned) {
return mMap->getDataPtr();
}
return ensureAlignment(mMap);
}
assert(mFp != NULL);
if (mLength < kReadVsMapThreshold) {
unsigned char* buf;
long allocLen;
/* zero-length files are allowed; not sure about zero-len allocs */
/* (works fine with gcc + x86linux) */
allocLen = mLength;
if (mLength == 0)
allocLen = 1;
buf = new unsigned char[allocLen];
if (buf == NULL) {
LOGE("alloc of %ld bytes failed\n", (long) allocLen);
return NULL;
}
LOGV("Asset %p allocating buffer size %d (smaller than threshold)", this, (int)allocLen);
if (mLength > 0) {
long oldPosn = ftell(mFp);
fseek(mFp, mStart, SEEK_SET);
if (fread(buf, 1, mLength, mFp) != (size_t) mLength) {
LOGE("failed reading %ld bytes\n", (long) mLength);
delete[] buf;
return NULL;
}
fseek(mFp, oldPosn, SEEK_SET);
}
LOGV(" getBuffer: loaded into buffer\n");
mBuf = buf;
return mBuf;
} else {
FileMap* map;
map = new FileMap;
if (!map->create(NULL, fileno(mFp), mStart, mLength, true)) {
map->release();
return NULL;
}
LOGV(" getBuffer: mapped\n");
mMap = map;
if (!wordAligned) {
return mMap->getDataPtr();
}
return ensureAlignment(mMap);
}
}