Mercurial > hg > dmlib
comparison src/dmres.c @ 1014:501ee5f0c043
Rename variables for consistency.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 01 Mar 2015 04:45:23 +0200 |
parents | ffd1ca99e456 |
children | 5101766dd95c |
comparison
equal
deleted
inserted
replaced
1013:1684bf6aa1f8 | 1014:501ee5f0c043 |
---|---|
454 | 454 |
455 | 455 |
456 static int dm_pack_preload(DMResource *handle) | 456 static int dm_pack_preload(DMResource *handle) |
457 { | 457 { |
458 DMPackEntry *node; | 458 DMPackEntry *node; |
459 int res = DMERR_OK; | 459 int ret = DMERR_OK; |
460 | 460 |
461 if (handle->lib == NULL || handle->lib->packFile == NULL) | 461 if (handle->lib == NULL || handle->lib->packFile == NULL) |
462 return DMERR_NULLPTR; | 462 return DMERR_NULLPTR; |
463 | 463 |
464 // Search PACK nodelist for file | 464 // Search PACK nodelist for file |
465 if ((node = dmPackFind(handle->lib->packFile->entries, handle->filename)) == NULL) | 465 if ((node = dmPackFind(handle->lib->packFile->entries, handle->filename)) == NULL) |
466 { | 466 { |
467 res = dmError(DMERR_NOT_FOUND, | 467 ret = dmError(DMERR_NOT_FOUND, |
468 "Entry '%s' not found in PACK file.\n", | 468 "Entry '%s' not found in PACK file.\n", |
469 handle->filename); | 469 handle->filename); |
470 goto out; | 470 goto out; |
471 } | 471 } |
472 | 472 |
473 // Seek to entry | 473 // Seek to entry |
474 if (fseek(handle->lib->packFile->file, node->offset, SEEK_SET) == -1) | 474 if (fseek(handle->lib->packFile->file, node->offset, SEEK_SET) == -1) |
475 { | 475 { |
476 res = dmError(DMERR_FSEEK, | 476 ret = dmError(DMERR_FSEEK, |
477 "Could not seek node position in PACK file.\n"); | 477 "Could not seek node position in PACK file.\n"); |
478 goto out; | 478 goto out; |
479 } | 479 } |
480 | 480 |
481 res = dm_pack_decompress(handle, node); | 481 res = dm_pack_decompress(handle, node); |
482 | 482 |
483 out: | 483 out: |
484 return res; | 484 return ret; |
485 } | 485 } |
486 | 486 |
487 | 487 |
488 static int dm_pack_fopen(DMResource * f) | 488 static int dm_pack_fopen(DMResource * f) |
489 { | 489 { |
490 if ((f->flags & DMF_LOADED_RAW) == 0) | 490 if ((f->flags & DMF_LOADED_RAW) == 0) |
491 { | 491 { |
492 int res = dm_pack_preload(f); | 492 int ret = dm_pack_preload(f); |
493 if (res == DMERR_OK) | 493 if (ret == DMERR_OK) |
494 f->flags |= DMF_LOADED_RAW; | 494 f->flags |= DMF_LOADED_RAW; |
495 | 495 |
496 return res; | 496 return ret; |
497 } | 497 } |
498 else | 498 else |
499 return DMERR_OK; | 499 return DMERR_OK; |
500 } | 500 } |
501 | 501 |
734 | 734 |
735 | 735 |
736 int dmf_open(DMResourceLib *lib, const char *filename, DMResource **phandle) | 736 int dmf_open(DMResourceLib *lib, const char *filename, DMResource **phandle) |
737 { | 737 { |
738 DMResource *handle; | 738 DMResource *handle; |
739 int res; | 739 int ret; |
740 | 740 |
741 // Check master directory for resource | 741 // Check master directory for resource |
742 if ((*phandle = handle = dmResourceFind(lib, filename)) == NULL) | 742 if ((*phandle = handle = dmResourceFind(lib, filename)) == NULL) |
743 { | 743 { |
744 #ifdef DM_USE_STDIO | 744 #ifdef DM_USE_STDIO |
758 return DMERR_INIT_FAIL; | 758 return DMERR_INIT_FAIL; |
759 #endif | 759 #endif |
760 } | 760 } |
761 | 761 |
762 // Check if the data is preloaded | 762 // Check if the data is preloaded |
763 if ((res = handle->fops->fopen(handle)) == DMERR_OK) | 763 if ((ret = handle->fops->fopen(handle)) == DMERR_OK) |
764 { | 764 { |
765 dmResourceRef(handle); | 765 dmResourceRef(handle); |
766 if (handle->flags & DMF_TEMPORARY) | 766 if (handle->flags & DMF_TEMPORARY) |
767 { | 767 { |
768 handle->flags &= ~DMF_TEMPORARY; | 768 handle->flags &= ~DMF_TEMPORARY; |
775 dmResourceFree(handle); | 775 dmResourceFree(handle); |
776 *phandle = handle = NULL; | 776 *phandle = handle = NULL; |
777 } | 777 } |
778 | 778 |
779 dmfreset(handle); | 779 dmfreset(handle); |
780 return res; | 780 return ret; |
781 } | 781 } |
782 | 782 |
783 | 783 |
784 int dmf_create_memio(DMResourceLib *lib, const char *filename, | 784 int dmf_create_memio(DMResourceLib *lib, const char *filename, |
785 Uint8 *buf, const size_t size, DMResource **phandle) | 785 Uint8 *buf, const size_t size, DMResource **phandle) |
960 | 960 |
961 | 961 |
962 #ifdef DM_USE_STDIO | 962 #ifdef DM_USE_STDIO |
963 static int dmResourcesLoadDirectory(DMResourceLib *lib, const char *path) | 963 static int dmResourcesLoadDirectory(DMResourceLib *lib, const char *path) |
964 { | 964 { |
965 int res = DMERR_OK; | 965 int ret = DMERR_OK; |
966 struct dirent *dh; | 966 struct dirent *dh; |
967 DIR *hdir = opendir(path); | 967 DIR *hdir = opendir(path); |
968 if (hdir == NULL) | 968 if (hdir == NULL) |
969 return dmGetErrno(); | 969 return dmGetErrno(); |
970 | 970 |
978 { | 978 { |
979 struct stat sbuf; | 979 struct stat sbuf; |
980 char *fname = dm_strdup_printf("%s/%s", path, dh->d_name); | 980 char *fname = dm_strdup_printf("%s/%s", path, dh->d_name); |
981 if (stat(fname, &sbuf) == -1) | 981 if (stat(fname, &sbuf) == -1) |
982 { | 982 { |
983 res = dmError(dmGetErrno(), | 983 ret = dmError(dmGetErrno(), |
984 "Could not stat() %s, #%d: %s\n", | 984 "Could not stat() %s, #%d: %s\n", |
985 fname, res, dmErrorStr(res)); | 985 fname, ret, dmErrorStr(ret)); |
986 dmFree(fname); | 986 dmFree(fname); |
987 goto out; | 987 goto out; |
988 } | 988 } |
989 | 989 |
990 if (S_ISREG(sbuf.st_mode)) | 990 if (S_ISREG(sbuf.st_mode)) |
1004 #ifdef __WIN32 | 1004 #ifdef __WIN32 |
1005 #else | 1005 #else |
1006 closedir(hdir); | 1006 closedir(hdir); |
1007 #endif | 1007 #endif |
1008 | 1008 |
1009 return res; | 1009 return ret; |
1010 } | 1010 } |
1011 #endif | 1011 #endif |
1012 | 1012 |
1013 | 1013 |
1014 /* Resources subsystem initialization and shutdown routines | 1014 /* Resources subsystem initialization and shutdown routines |
1118 | 1118 |
1119 // Shutdown possible subsystems | 1119 // Shutdown possible subsystems |
1120 #ifdef DM_USE_PACKFS | 1120 #ifdef DM_USE_PACKFS |
1121 if (lib->flags & DRF_USE_PACK) | 1121 if (lib->flags & DRF_USE_PACK) |
1122 { | 1122 { |
1123 int res = dmPackClose(lib->packFile); | 1123 int ret = dmPackClose(lib->packFile); |
1124 if (res != DMERR_OK) | 1124 if (ret != DMERR_OK) |
1125 { | 1125 { |
1126 dmError(res, "Error closing PACK, #%i: %s\n", | 1126 dmError(ret, "Error closing PACK, #%i: %s\n", |
1127 res, dmErrorStr(res)); | 1127 ret, dmErrorStr(ret)); |
1128 } | 1128 } |
1129 | 1129 |
1130 dmFree(lib->packFilename); | 1130 dmFree(lib->packFilename); |
1131 } | 1131 } |
1132 #endif | 1132 #endif |