Skip to content

Commit 3be85fe

Browse files
author
Jon Daniel
committed
fix TAR not loading
1 parent 0f54b25 commit 3be85fe

4 files changed

Lines changed: 24 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ if(NOT PHYSFS_ARCHIVE_WAD)
126126
add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
127127
endif()
128128

129+
option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE)
130+
if(NOT PHYSFS_ARCHIVE_TAR)
131+
add_definitions(-DPHYSFS_SUPPORTS_TAR=0)
132+
endif()
133+
129134
option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE)
130135
if(NOT PHYSFS_ARCHIVE_CSM)
131136
add_definitions(-DPHYSFS_SUPPORTS_CSM=0)
132137
endif()
133138

134-
option(PHYSFS_ARCHIVE_TAR "Enable POSIX TAR / Chasm: The Rift [Demo] Remastered csm.bin support" TRUE)
135-
if(NOT PHYSFS_ARCHIVE_TAR)
136-
add_definitions(-DPHYSFS_SUPPORTS_TAR=0)
137-
endif()
138139

139140
option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
140141
if(NOT PHYSFS_ARCHIVE_HOG)

src/physfs_archiver_tar.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
#if PHYSFS_SUPPORTS_TAR
1313
#include "physfs_tar.h"
1414

15-
static bool TAR_loadEntries(PHYSFS_Io *io, void *arc)
15+
static int TAR_loadEntries(PHYSFS_Io *io, void *arc)
1616
{
17-
union block zero_block;
18-
union block current_block;
17+
union block zero_block = { 0 };
18+
union block current_block = { 0 };
1919
PHYSFS_uint64 count = 0;
2020
bool long_name = false;
2121

22-
memset(zero_block.buffer, 0, sizeof(BLOCKSIZE));
23-
memset(current_block.buffer, 0, sizeof(BLOCKSIZE));
24-
2522
/* read header block until zero-only terminated block */
26-
for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE); count++)
23+
for(; __PHYSFS_readAll(io, current_block.buffer, BLOCKSIZE) != 0; count++)
2724
{
2825
if( memcmp(current_block.buffer, zero_block.buffer, BLOCKSIZE) == 0 )
29-
return true;
26+
return 1;
3027

3128
/* verify magic */
3229
switch(TAR_magic(&current_block))
@@ -49,35 +46,34 @@ static bool TAR_loadEntries(PHYSFS_Io *io, void *arc)
4946
}
5047
}
5148

52-
return false;
49+
return 0;
5350
}
5451

5552
static void *TAR_openArchive(PHYSFS_Io *io, const char *name,
5653
int forWriting, int *claimed)
5754
{
5855
void *unpkarc = NULL;
59-
union block first;
60-
enum archive_format format;
56+
char buf[BLOCKSIZE] = { '\0' };
6157

6258
assert(io != NULL); /* shouldn't ever happen. */
6359

6460
BAIL_IF(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
61+
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL);
62+
if ((memcmp(&buf[TMAGOFF], TMAGIC, TMAGLEN - 1) != 0) != 0)
63+
BAIL(PHYSFS_ERR_UNSUPPORTED, NULL);
6564

66-
BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, first.buffer, BLOCKSIZE), NULL);
67-
format = TAR_magic(&first);
68-
io->seek(io, 0);
69-
*claimed = format == DEFAULT_FORMAT ? 0 : 1;
65+
*claimed = 1;
7066

71-
unpkarc = UNPK_openArchive(io, 0, 1);
67+
BAIL_IF_ERRPASS(!io->seek(io, 0), 0);
68+
unpkarc = UNPK_openArchive(io, 1, 0);
7269
BAIL_IF_ERRPASS(!unpkarc, NULL);
7370

74-
if (!TAR_loadEntries(io, unpkarc))
71+
if (TAR_loadEntries(io, unpkarc) == 0)
7572
{
7673
UNPK_abandonArchive(unpkarc);
7774
return NULL;
7875
} /* if */
7976

80-
8177
return unpkarc;
8278
} /* TAR_openArchive */
8379

src/physfs_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ extern const PHYSFS_Archiver __PHYSFS_Archiver_QPAK;
8888
extern const PHYSFS_Archiver __PHYSFS_Archiver_HOG;
8989
extern const PHYSFS_Archiver __PHYSFS_Archiver_MVL;
9090
extern const PHYSFS_Archiver __PHYSFS_Archiver_WAD;
91-
extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM;
9291
extern const PHYSFS_Archiver __PHYSFS_Archiver_TAR;
92+
extern const PHYSFS_Archiver __PHYSFS_Archiver_CSM;
9393
extern const PHYSFS_Archiver __PHYSFS_Archiver_SLB;
9494
extern const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660;
9595
extern const PHYSFS_Archiver __PHYSFS_Archiver_VDF;
@@ -202,12 +202,12 @@ void __PHYSFS_smallFree(void *ptr);
202202
#ifndef PHYSFS_SUPPORTS_WAD
203203
#define PHYSFS_SUPPORTS_WAD PHYSFS_SUPPORTS_DEFAULT
204204
#endif
205-
#ifndef PHYSFS_SUPPORTS_CSM
206-
#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT
207-
#endif
208205
#ifndef PHYSFS_SUPPORTS_TAR
209206
#define PHYSFS_SUPPORTS_TAR PHYSFS_SUPPORTS_DEFAULT
210207
#endif
208+
#ifndef PHYSFS_SUPPORTS_CSM
209+
#define PHYSFS_SUPPORTS_CSM PHYSFS_SUPPORTS_DEFAULT
210+
#endif
211211
#ifndef PHYSFS_SUPPORTS_QPAK
212212
#define PHYSFS_SUPPORTS_QPAK PHYSFS_SUPPORTS_DEFAULT
213213
#endif

src/physfs_tar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define TMAGIC "ustar" /* ustar and a null */
2727
#define OLDGNU_MAGIC "ustar " /* 7 chars and a null */
2828
#define TMAGLEN 6
29-
29+
#define TMAGOFF 257
3030
#define TVERSION "00" /* 00 and no null */
3131
#define TVERSLEN 2
3232

0 commit comments

Comments
 (0)