bool MCCacheWriter::writeAll() { #define WRITE_SECTION(NAME, OFFSET, SIZE, SECTION) \ do { \ if (mInfoFile->seek(OFFSET, SEEK_SET) == -1) { \ ALOGE("Unable to seek to " #NAME " section for writing.\n"); \ return false; \ } \ \ if (mInfoFile->write(reinterpret_cast<char *>(SECTION), (SIZE)) != \ static_cast<ssize_t>(SIZE)) { \ ALOGE("Unable to write " #NAME " section to cache file.\n"); \ return false; \ } \ } while (0) #define WRITE_SECTION_SIMPLE(NAME, SECTION) \ WRITE_SECTION(NAME, \ mpHeaderSection->NAME##_offset, \ mpHeaderSection->NAME##_size, \ SECTION) WRITE_SECTION(header, 0, sizeof(MCO_Header), mpHeaderSection); WRITE_SECTION_SIMPLE(str_pool, mpStringPoolSection); WRITE_SECTION_SIMPLE(depend_tab, mpDependencyTableSection); WRITE_SECTION_SIMPLE(pragma_list, mpPragmaListSection); WRITE_SECTION_SIMPLE(object_slot_list, mpObjectSlotSection); WRITE_SECTION_SIMPLE(export_var_name_list, mpExportVarNameListSection); WRITE_SECTION_SIMPLE(export_func_name_list, mpExportFuncNameListSection); WRITE_SECTION_SIMPLE(export_foreach_name_list, mpExportForEachNameListSection); #undef WRITE_SECTION_SIMPLE #undef WRITE_SECTION if (static_cast<size_t>(mObjFile->write(mpOwner->getELF(), mpOwner->getELFSize())) != mpOwner->getELFSize()) { ALOGE("Unable to write ELF to cache file.\n"); return false; } return true; }
void write_groups(struct storage *store, const faction * f) { group *g; for (g = f->groups; g; g = g->next) { ally *a; WRITE_INT(store, g->gid); WRITE_STR(store, g->name); for (a = g->allies; a; a = a->next) { if (a->faction) { write_faction_reference(a->faction, store); WRITE_INT(store, a->status); } } WRITE_INT(store, 0); a_write(store, g->attribs, g); WRITE_SECTION(store); } WRITE_INT(store, 0); }
void write_borders(struct storage *store) { int i; for (i = 0; i != BORDER_MAXHASH; ++i) { connection *bhash; for (bhash = borders[i]; bhash; bhash = bhash->nexthash) { connection *b; for (b = bhash; b != NULL; b = b->next) { if (b->type->valid && !b->type->valid(b)) continue; WRITE_TOK(store, b->type->__name); WRITE_INT(store, b->id); WRITE_INT(store, b->from->uid); WRITE_INT(store, b->to->uid); if (b->type->write) b->type->write(b, store); WRITE_SECTION(store); } } } WRITE_TOK(store, "end"); }