static int CacheSaveModuleConfig (FILE *file, const module_t *module) { uint16_t lines = module->confsize; SAVE_IMMEDIATE (module->i_config_items); SAVE_IMMEDIATE (module->i_bool_items); SAVE_IMMEDIATE (lines); for (size_t i = 0; i < lines; i++) if (CacheSaveConfig (file, module->p_config + i)) goto error; return 0; error: return -1; }
static int CacheSaveBank (FILE *file, const module_cache_t *cache, size_t i_cache) { uint32_t i_file_size = 0; /* Contains version number */ if (fputs (CACHE_STRING, file) == EOF) goto error; #ifdef DISTRO_VERSION /* Allow binary maintaner to pass a string to detect new binary version*/ if (fputs( DISTRO_VERSION, file ) == EOF) goto error; #endif /* Sub-version number (to avoid breakage in the dev version when cache * structure changes) */ i_file_size = CACHE_SUBVERSION_NUM; if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1 ) goto error; /* Header marker */ i_file_size = ftell( file ); if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1) goto error; if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1) goto error; #define SAVE_IMMEDIATE( a ) \ if (fwrite (&a, sizeof(a), 1, file) != 1) \ goto error #define SAVE_STRING( a ) \ { \ uint16_t i_size = (a != NULL) ? (strlen (a) + 1) : 0; \ if ((fwrite (&i_size, sizeof (i_size), 1, file) != 1) \ || (a && (fwrite (a, 1, i_size, file) != i_size))) \ goto error; \ } while(0) for (unsigned i = 0; i < i_cache; i++) { module_t *module = cache[i].p_module; uint32_t i_submodule; /* Save additional infos */ SAVE_STRING(module->psz_shortname); SAVE_STRING(module->psz_longname); SAVE_STRING(module->psz_help); SAVE_IMMEDIATE(module->i_shortcuts); for (unsigned j = 0; j < module->i_shortcuts; j++) SAVE_STRING(module->pp_shortcuts[j]); SAVE_STRING(module->psz_capability); SAVE_IMMEDIATE(module->i_score); SAVE_IMMEDIATE(module->b_unloadable); /* Config stuff */ if (CacheSaveConfig (file, module)) goto error; SAVE_STRING(module->domain); i_submodule = module->submodule_count; SAVE_IMMEDIATE( i_submodule ); if (CacheSaveSubmodule (file, module->submodule)) goto error; /* Save common info */ SAVE_STRING(cache[i].path); SAVE_IMMEDIATE(cache[i].mtime); SAVE_IMMEDIATE(cache[i].size); } if (fflush (file)) /* flush libc buffers */ goto error; return 0; /* success! */ error: return -1; }