X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=pak.c;h=0b3f2216e2b4777c7892cedc0d04f72dfd4378f4;hp=abb389bc0a2fa30b245a42712b960125876e40e8;hb=e50b7a27191372a333f5c9f3ffbbfaab9fb85522;hpb=bee14a6df7100de5d68c1b53fc820c98eb9123cb diff --git a/pak.c b/pak.c index abb389b..0b3f221 100644 --- a/pak.c +++ b/pak.c @@ -304,7 +304,7 @@ static bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdi mem_d(dat); return true; - + err: if (dat) mem_d(dat); if (out) fs_file_close(out); @@ -351,11 +351,10 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { * the directory entry, and the actual contents of the file * to the PAK file itself. */ - if (fs_file_seek(fp, 0, SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0)) { - fs_file_close(fp); - return false; - } - fs_file_seek(fp, 0, SEEK_SET); + if (fs_file_seek(fp, 0, SEEK_END) != 0 || ((len = fs_file_tell(fp)) < 0)) + goto err; + if (fs_file_seek(fp, 0, SEEK_SET) != 0) + goto err; dir.len = len; dir.pos = fs_file_tell(pak->handle); @@ -364,10 +363,8 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { * We're limited to 56 bytes for a file name string, that INCLUDES * the directory and '/' seperators. */ - if (strlen(file) >= 56) { - fs_file_close(fp); - return false; - } + if (strlen(file) >= 56) + goto err; util_strncpy(dir.name, file, strlen(file)); @@ -375,10 +372,8 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { * Allocate some memory for loading in the data that will be * redirected into the PAK file. */ - if (!(dat = (unsigned char *)mem_a(dir.len))) { - fs_file_close(fp); - return false; - } + if (!(dat = (unsigned char *)mem_a(dir.len))) + goto err; fs_file_read (dat, dir.len, 1, fp); fs_file_close(fp); @@ -391,13 +386,18 @@ static bool pak_insert_one(pak_file_t *pak, const char *file) { vec_push(pak->directories, dir); return true; + +err: + fs_file_close(fp); + return false; } /* * Like pak_insert_one, except this collects files in all directories * from a root directory, and inserts them all. */ -bool pak_insert_all(pak_file_t *pak, const char *dir) { +#if 0 +static bool pak_insert_all(pak_file_t *pak, const char *dir) { DIR *dp; struct dirent *dirp; @@ -417,6 +417,7 @@ bool pak_insert_all(pak_file_t *pak, const char *dir) { fs_dir_close(dp); return true; } +#endif /*!if 0 renable when ready to use */ static bool pak_close(pak_file_t *pak) { size_t itr;