# HG changeset patch # User Matti Hamalainen # Date 1365748461 -10800 # Node ID c1a5652e473de965c15407f86c4c8ddcf43dd411 # Parent 588998ccc07a15a1626c0de2e1851ed562b511a4 Sanitize resource preloading function a bit. diff -r 588998ccc07a -r c1a5652e473d dmres.c --- a/dmres.c Fri Apr 12 08:21:49 2013 +0300 +++ b/dmres.c Fri Apr 12 09:34:21 2013 +0300 @@ -572,12 +572,12 @@ #ifdef DM_USE_PACKFS if (handle->lib->flags & DRF_USE_PACK) handle->fops = &dfPackFileOps; -#ifdef DM_USE_STDIO +# ifdef DM_USE_STDIO else handle->fops = &dfStdioFileOps; -#else +# else handle->fops = &dfPackFileOps; -#endif +# endif #else handle->fops = NULL; @@ -591,47 +591,44 @@ int ret = DMERR_INIT_FAIL; // Check if we want to preload raw data? - if (((handle->flags & DMF_PRELOAD_RAW) || - (handle->lib->flags & DRF_PRELOAD_ALL)) && - (handle->flags & DMF_LOADED_RAW) == 0 && - handle->fops->preload != NULL) + if ((handle->flags & DMF_PRELOAD_RAW) || + (handle->lib->flags & DRF_PRELOAD_ALL)) { - ret = handle->fops->preload(handle); - if (ret == DMERR_OK) + if (handle->flags & DMF_LOADED_RAW) + ret = DMERR_OK; + else + if (handle->fops->preload != NULL) { - handle->flags |= DMF_LOADED_RAW; + ret = handle->fops->preload(handle); + if (ret == DMERR_OK) + handle->flags |= DMF_LOADED_RAW; } } else { if (handle->fops->fopen != NULL) ret = handle->fops->fopen(handle); - else - if (handle->fops->preload != NULL) - { - ret = handle->fops->preload(handle); - if (ret == DMERR_OK) - { - handle->flags |= DMF_LOADED_RAW; - } - } } // Check if resource data is to be preloaded - if (((handle->flags & DMF_PRELOAD_RES) || (handle->lib->flags & DRF_PRELOAD_RES)) && - (handle->flags & DMF_LOADED_RES) == 0 && - handle->rops != NULL && - handle->rops->load != NULL) + if ((handle->flags & DMF_PRELOAD_RES) || (handle->lib->flags & DRF_PRELOAD_RES)) { - ret = handle->rops->load(handle); - if (ret == DMERR_OK) + if (handle->flags & DMF_LOADED_RES) + ret = DMERR_OK; + else + if (handle->rops != NULL && + handle->rops->load != NULL) { - // Okay, mark as loaded - handle->flags |= DMF_LOADED_RES; + ret = handle->rops->load(handle); + if (ret == DMERR_OK) + { + // Okay, mark as loaded + handle->flags |= DMF_LOADED_RES; - // Check if we can purge the raw data now - if ((handle->flags & DMF_PERSIST) == 0) - dmres_purge_raw_data(handle); + // Check if we can purge the raw data now + if ((handle->flags & DMF_PERSIST) == 0) + dmres_purge_raw_data(handle); + } } } diff -r 588998ccc07a -r c1a5652e473d dmres.h --- a/dmres.h Fri Apr 12 08:21:49 2013 +0300 +++ b/dmres.h Fri Apr 12 09:34:21 2013 +0300 @@ -153,6 +153,7 @@ DMResource * dmf_create_stdio_stream(FILE *); #endif void dmf_close(DMResource *); +int dmf_preload(DMResource *); // Basic resource access functions