1
0
forked from 0ad/0ad

slight change to error paths for convenience (RETURN_ERR)

This was SVN commit r2068.
This commit is contained in:
janwas 2005-03-27 17:40:40 +00:00
parent 2fa430a4e6
commit 36cd555ba7
3 changed files with 14 additions and 15 deletions

View File

@ -118,6 +118,15 @@ STMT(\
)
#endif
// just pass on errors without any kind of annoying warning
// (useful for functions that can legitimately fail, e.g. vfs_exists).
#define RETURN_ERR(func)\
STMT(\
int err__ = (int)((func) & UINT_MAX);\
if(err__ < 0)\
return err__;\
)
#define THROW_ERR(func)\
STMT(\
int err__ = (int)((func) & UINT_MAX);\

View File

@ -648,9 +648,8 @@ int tree_lookup_dir(const char* path, TDir** pdir, uint flags, char* exact_path)
TDir* dir = (flags & LF_START_DIR)? *pdir : tree_root_dir;
TNode* node;
int err = dir->lookup(path, flags, &node, exact_path);
if(err <= 0)
CHECK_ERR(err);
CHECK_ERR(dir->lookup(path, flags, &node, exact_path));
// directories should exist, so warn if this fails
*pdir = &node->u.dir;
return 0;
}
@ -664,8 +663,7 @@ int tree_lookup(const char* path, TFile** pfile, uint flags, char* exact_path)
TNode* node;
int ret = tree_root_dir->lookup(path, flags, &node, exact_path);
if(ret < 0) // xxx
return ret;
RETURN_ERR(ret);
*pfile = &node->u.file;
return 0;
}

View File

@ -487,8 +487,7 @@ static int lookup_init(LookupInfo* li, const u8* file, const size_t size)
// the VFS blindly opens files when mounting; it needs to open
// all archives, but doesn't know their extension (e.g. ".pk3").
err = z_validate(file, size);
if(err < 0) // don't CHECK_ERR - this can happen often.
return err;
RETURN_ERR(err);
li->next_file = 0;
li->idx = new LookupIdx;
@ -926,14 +925,7 @@ static int zfile_validate(uint line, ZFile* zf)
return err;
}
#define CHECK_ZFILE(f)\
do\
{\
int err = zfile_validate(__LINE__, f);\
if(err < 0)\
return err;\
}\
while(0);
#define CHECK_ZFILE(f) CHECK_ERR(zfile_validate(__LINE__, f))
// convenience function, allows implementation change in ZFile.