Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not mistake WAD-named directories for actual WAD files #2118

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/d_iwad.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,6 @@ static void CheckDOSDefaults(void)

#endif

// Returns true if the specified path is a path to a file
// of the specified name.

static boolean DirIsFile(const char *path, const char *filename)
{
return strchr(path, DIR_SEPARATOR) != NULL
&& !strcasecmp(M_BaseName(path), filename);
}

// Add IWAD directories parsed from splitting a path string containing
// paths separated by PATH_SEPARATOR. 'suffix' is a string to concatenate
// to the end of the paths before adding them.
Expand Down Expand Up @@ -624,7 +615,6 @@ void BuildIWADDirList(void)

char *D_FindWADByName(const char *name)
{
char *path;
char *probe;

// Absolute path?
Expand All @@ -647,15 +637,15 @@ char *D_FindWADByName(const char *name)
// file.

probe = M_FileCaseExists(*dir);
if (DirIsFile(*dir, name) && probe != NULL)
if (probe != NULL)
{
return probe;
}
free(probe);

// Construct a string for the full path

path = M_StringJoin(*dir, DIR_SEPARATOR_S, name);
char *path = M_StringJoin(*dir, DIR_SEPARATOR_S, name);

probe = M_FileCaseExists(path);
if (probe != NULL)
Expand Down
19 changes: 8 additions & 11 deletions src/m_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

// Check if a file exists

boolean M_FileExists(const char *filename)
static boolean M_FileExistsNotDir(const char *filename)
{
FILE *fstream;

Expand All @@ -45,14 +45,11 @@ boolean M_FileExists(const char *filename)
if (fstream != NULL)
{
fclose(fstream);
return true;
return M_DirExists(filename) == false;
}
else
{
// If we can't open because the file is a directory, the
// "file" exists at least!

return errno == EISDIR;
return false;
}
}

Expand Down Expand Up @@ -118,7 +115,7 @@ char *M_FileCaseExists(const char *path)
path_dup = M_StringDuplicate(path);

// 0: actual path
if (M_FileExists(path_dup))
if (M_FileExistsNotDir(path_dup))
{
return path_dup;
}
Expand All @@ -130,15 +127,15 @@ char *M_FileCaseExists(const char *path)
// 1: lowercase filename, e.g. doom2.wad
M_StringToLower(filename);

if (M_FileExists(path_dup))
if (M_FileExistsNotDir(path_dup))
{
return path_dup;
}

// 2: uppercase filename, e.g. DOOM2.WAD
M_StringToUpper(filename);

if (M_FileExists(path_dup))
if (M_FileExistsNotDir(path_dup))
{
return path_dup;
}
Expand All @@ -149,7 +146,7 @@ char *M_FileCaseExists(const char *path)
{
M_StringToLower(ext + 1);

if (M_FileExists(path_dup))
if (M_FileExistsNotDir(path_dup))
{
return path_dup;
}
Expand All @@ -160,7 +157,7 @@ char *M_FileCaseExists(const char *path)
{
M_StringToLower(filename + 1);

if (M_FileExists(path_dup))
if (M_FileExistsNotDir(path_dup))
{
return path_dup;
}
Expand Down
1 change: 0 additions & 1 deletion src/m_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "doomtype.h"

boolean M_FileExists(const char *file);
boolean M_DirExists(const char *path);
int M_FileLength(const char *path);
char *M_TempFile(const char *s);
Expand Down