From 389a4d826a3e6b125853dc33e4da69e19f0624f0 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 13 Mar 2005 03:33:11 +0000 Subject: [PATCH] Cleaned up some minor bloat with my new evil GOTO_*_MACRO macros. --- archivers/grp.c | 6 +----- archivers/hog.c | 6 +----- archivers/mix.c | 16 ++++------------ archivers/mvl.c | 7 +------ archivers/qpak.c | 15 ++++----------- archivers/wad.c | 6 +----- platform/unix.c | 6 +----- 7 files changed, 13 insertions(+), 49 deletions(-) diff --git a/archivers/grp.c b/archivers/grp.c index e882e369..7b40f8fa 100644 --- a/archivers/grp.c +++ b/archivers/grp.c @@ -270,11 +270,7 @@ static void *GRP_openArchive(const char *name, int forWriting) memset(info, '\0', sizeof (GRPinfo)); info->filename = (char *) malloc(strlen(name) + 1); - if (info->filename == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto GRP_openArchive_failed; - } /* if */ + GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, GRP_openArchive_failed); if (!grp_load_entries(name, forWriting, info)) goto GRP_openArchive_failed; diff --git a/archivers/hog.c b/archivers/hog.c index 3fd82bfd..73e6a9f6 100644 --- a/archivers/hog.c +++ b/archivers/hog.c @@ -309,11 +309,7 @@ static void *HOG_openArchive(const char *name, int forWriting) BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0); memset(info, '\0', sizeof (HOGinfo)); info->filename = (char *) malloc(strlen(name) + 1); - if (info->filename == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto HOG_openArchive_failed; - } /* if */ + GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed); if (!hog_load_entries(name, forWriting, info)) goto HOG_openArchive_failed; diff --git a/archivers/mix.c b/archivers/mix.c index 7a70081e..2434adff 100644 --- a/archivers/mix.c +++ b/archivers/mix.c @@ -236,12 +236,8 @@ static void *MIX_openArchive(const char *name, int forWriting) memset(info, '\0', sizeof (MIXinfo)); info->filename = (char *) malloc(strlen(name) + 1); - if (info->filename == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto MIX_openArchive_failed; - } /* if */ - + GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MIX_openArchive_failed); + /* store filename */ strcpy(info->filename, name); @@ -259,12 +255,8 @@ static void *MIX_openArchive(const char *name, int forWriting) /* allocate space for the entries and read the entries */ info->entry = malloc(sizeof (MIXentry) * info->header.num_files); - if (info->entry == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto MIX_openArchive_failed; - } /* if */ - + GOTO_IF_MACRO(!info->entry, ERR_OUT_OF_MEMORY, MIX_openArchive_failed); + /* read the directory list */ for (i = 0; i < header.num_files; i++) { diff --git a/archivers/mvl.c b/archivers/mvl.c index d2ece80f..33021541 100644 --- a/archivers/mvl.c +++ b/archivers/mvl.c @@ -268,12 +268,7 @@ static void *MVL_openArchive(const char *name, int forWriting) memset(info, '\0', sizeof (MVLinfo)); info->filename = (char *) malloc(strlen(name) + 1); - if (info->filename == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto MVL_openArchive_failed; - } /* if */ - + GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MVL_openArchive_failed); if (!mvl_load_entries(name, forWriting, info)) goto MVL_openArchive_failed; diff --git a/archivers/qpak.c b/archivers/qpak.c index a59dc174..7dad0e7e 100644 --- a/archivers/qpak.c +++ b/archivers/qpak.c @@ -75,7 +75,7 @@ typedef struct } QPAKfileinfo; /* Magic numbers... */ -#define QPAK_SIGNATURE 0x4b434150 /* "PACK" in ASCII. */ +#define QPAK_SIG 0x4b434150 /* "PACK" in ASCII. */ static void QPAK_dirClose(dvoid *opaque) @@ -175,11 +175,7 @@ static int qpak_open(const char *filename, int forWriting, goto openQpak_failed; buf = PHYSFS_swapULE32(buf); - if (buf != QPAK_SIGNATURE) - { - __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE); - goto openQpak_failed; - } /* if */ + GOTO_IF_MACRO(buf != QPAK_SIG, ERR_UNSUPPORTED_ARCHIVE, openQpak_failed); if (__PHYSFS_platformRead(*fh, &buf, sizeof (PHYSFS_uint32), 1) != 1) goto openQpak_failed; @@ -191,11 +187,8 @@ static int qpak_open(const char *filename, int forWriting, *count = PHYSFS_swapULE32(*count); - if ((*count % 64) != 0) /* corrupted archive? */ - { - __PHYSFS_setError(ERR_CORRUPTED); - goto openQpak_failed; - } /* if */ + /* corrupted archive? */ + GOTO_IF_MACRO((*count % 64) != 0, ERR_CORRUPTED, openQpak_failed); if (!__PHYSFS_platformSeek(*fh, buf)) goto openQpak_failed; diff --git a/archivers/wad.c b/archivers/wad.c index f1657995..c28628fd 100644 --- a/archivers/wad.c +++ b/archivers/wad.c @@ -298,11 +298,7 @@ static void *WAD_openArchive(const char *name, int forWriting) memset(info, '\0', sizeof (WADinfo)); info->filename = (char *) malloc(strlen(name) + 1); - if (info->filename == NULL) - { - __PHYSFS_setError(ERR_OUT_OF_MEMORY); - goto WAD_openArchive_failed; - } /* if */ + GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, WAD_openArchive_failed); if (!wad_load_entries(name, forWriting, info)) goto WAD_openArchive_failed; diff --git a/platform/unix.c b/platform/unix.c index fdb3c126..9d4a9bb6 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -219,11 +219,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) struct mntent *ent = NULL; mounts = setmntent("/etc/mtab", "r"); - if (mounts == NULL) - { - __PHYSFS_setError(ERR_IO_ERROR); - return; - } /* if */ + BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, /*return void*/); while ( (ent = getmntent(mounts)) != NULL ) {