Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Replace win_fopen.c with wrappers used in Chocolate Doom #554

Merged
merged 4 commits into from
Dec 23, 2022
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ cmake_install.cmake
/prboom2/prboom-plus
/prboom2/prboom-plus-game-server
/prboom2/prboom-plus.wad
/prboom2/build*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this some time ago by mistake when I was implementing win_fopen.c.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay.

12 changes: 2 additions & 10 deletions prboom2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ set(COMMON_SRC
m_menu.h
m_misc.c
m_misc.h
m_io.c
m_io.h
m_random.c
m_random.h
m_swap.h
Expand Down Expand Up @@ -301,8 +303,6 @@ function(AddGameExecutable TARGET SOURCES)
e6y_launcher.c
e6y_launcher.h
SDL/SDL_windows_main.c
WIN/win_fopen.c
WIN/win_fopen.h
)
if(MSVC)
set(SOURCES
Expand Down Expand Up @@ -417,14 +417,6 @@ if(BUILD_SERVER AND SDL2_NET_FOUND)
protocol.h
SDL/i_network.c
)

if(WIN32)
set(PRBOOM_PLUS_GAME_SERVER_SOURCES
${PRBOOM_PLUS_GAME_SERVER_SOURCES}
WIN/win_fopen.c
WIN/win_fopen.h
)
endif()
if(MSVC)
set(PRBOOM_PLUS_GAME_SERVER_SOURCES
${PRBOOM_PLUS_GAME_SERVER_SOURCES}
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/MAC/i_sound.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int I_RegisterSong(const void *data, size_t len)

if ( music_tmp == NULL )
return 0;
midfile = fopen(music_tmp, "wb");
midfile = M_fopen(music_tmp, "wb");
if ( midfile == NULL ) {
lprintf(LO_ERROR,"Couldn't write MIDI to %s\n", music_tmp);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/MUSIC/midifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ int main(int argc, char *argv[])
printf("Usage: %s <filename>\n", argv[0]);
exit(1);
}
f = fopen (argv[1], "rb");
f = M_fopen (argv[1], "rb");
if (!f)
{
fprintf(stderr, "Failed to open %s\n", argv[1]);
Expand Down
22 changes: 10 additions & 12 deletions prboom2/src/SDL/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@

#include "z_zone.h"

#ifdef _WIN32
#include "../WIN/win_fopen.h"
#endif
#include "m_io.h"

void I_uSleep(unsigned long usecs)
{
Expand Down Expand Up @@ -189,7 +187,7 @@ dboolean I_FileToBuffer(const char *filename, byte **data, int *size)
byte *buffer = NULL;
size_t filesize = 0;

hfile = fopen(filename, "rb");
hfile = M_fopen(filename, "rb");
if (hfile)
{
fseek(hfile, 0, SEEK_END);
Expand Down Expand Up @@ -301,11 +299,11 @@ const char *I_DoomExeDir(void)
*p--=0;
if (*p=='/' || *p=='\\')
*p--=0;
if (strlen(base)<2 || access(base, W_OK) != 0)
if (strlen(base)<2 || M_access(base, W_OK) != 0)
{
free(base);
base = (char*)malloc(1024);
if (!getcwd(base,1024) || access(base, W_OK) != 0)
if (!M_getcwd(base,1024) || M_access(base, W_OK) != 0)
strcpy(base, current_dir_dummy);
}
}
Expand Down Expand Up @@ -353,7 +351,7 @@ const char *I_DoomExeDir(void)

if (!base) // cache multiple requests
{
char *home = getenv("HOME");
char *home = M_getenv("HOME");
char *p_home = strdup(home);
size_t len = strlen(home);
size_t p_len = (len + strlen(prboom_dir) + 3);
Expand All @@ -367,7 +365,7 @@ const char *I_DoomExeDir(void)

// if ~/.$prboom_dir doesn't exist,
// create and use directory in XDG_DATA_HOME
if (stat(base, &data_dir) || !S_ISDIR(data_dir.st_mode))
if (M_stat(base, &data_dir) || !S_ISDIR(data_dir.st_mode))
{
// SDL creates this directory if it doesn't exist
char *prefpath = SDL_GetPrefPath("", prboom_dir);
Expand Down Expand Up @@ -471,7 +469,7 @@ char* I_FindFileInternal(const char* wfname, const char* ext, dboolean isStatic)
memcpy(search, search0, num_search * sizeof(*search));

// add each directory from the $DOOMWADPATH environment variable
if ((dwp = getenv("DOOMWADPATH")))
if ((dwp = M_getenv("DOOMWADPATH")))
{
char *left, *ptr, *dup_dwp;

Expand Down Expand Up @@ -517,7 +515,7 @@ char* I_FindFileInternal(const char* wfname, const char* ext, dboolean isStatic)
* and optionally s to a subdirectory of d */
// switch replaced with lookup table
if (search[i].env) {
if (!(d = getenv(search[i].env)))
if (!(d = M_getenv(search[i].env)))
continue;
} else if (search[i].func)
d = search[i].func();
Expand All @@ -531,9 +529,9 @@ char* I_FindFileInternal(const char* wfname, const char* ext, dboolean isStatic)
s ? s : "", (s && !HasTrailingSlash(s)) ? "/" : "",
wfname);

if (ext && access(p,F_OK))
if (ext && M_access(p,F_OK))
strcat(p, ext);
if (!access(p,F_OK)) {
if (!M_access(p,F_OK)) {
if (!isStatic)
lprintf(LO_INFO, " found %s\n", p);
return p;
Expand Down
126 changes: 0 additions & 126 deletions prboom2/src/WIN/win_fopen.c

This file was deleted.

54 changes: 0 additions & 54 deletions prboom2/src/WIN/win_fopen.h

This file was deleted.

8 changes: 3 additions & 5 deletions prboom2/src/d_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@
#include "lprintf.h"
#include "e6y.h"

#ifdef _WIN32
#include "WIN/win_fopen.h"
#endif
#include "m_io.h"

static dboolean server;
static int remotetic; // Tic expected from the remote
Expand Down Expand Up @@ -249,7 +247,7 @@ dboolean D_NetGetWad(const char* name)
}
/* This is the parent, i.e. main LxDoom process */
wait(&rv);
if (!(done = !access(name, R_OK))) {
if (!(done = !M_access(name, R_OK))) {
if (!strcmp(p+strlen(p)-4, ".zip")) {
p = strrchr(p, '/')+1;
if ((pid = fork()) == -1)
Expand All @@ -260,7 +258,7 @@ dboolean D_NetGetWad(const char* name)
}
/* Parent waits for the file */
wait(&rv);
done = !!access(name, R_OK);
done = !!M_access(name, R_OK);
}
/* Add more decompression protocols here as desired */
}
Expand Down
8 changes: 3 additions & 5 deletions prboom2/src/d_deh.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
// CPhipps - modify to use logical output routine
#include "lprintf.h"

#ifdef _WIN32
#include "WIN/win_fopen.h"
#endif
#include "m_io.h"

#define TRUE 1
#define FALSE 0
Expand Down Expand Up @@ -1613,7 +1611,7 @@ void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)
if (!strcmp(outfilename, "-"))
fileout = stdout;
else
if (!(fileout=fopen(outfilename, firstfile ? "wt" : "at")))
if (!(fileout=M_fopen(outfilename, firstfile ? "wt" : "at")))
{
lprintf(LO_WARN, "Could not open -dehout file %s\n... using stdout.\n",
outfilename);
Expand All @@ -1626,7 +1624,7 @@ void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)

if (filename)
{
if (!(infile.f = fopen(filename,"rt")))
if (!(infile.f = M_fopen(filename,"rt")))
{
lprintf(LO_WARN, "-deh file %s not found\n",filename);
return; // should be checked up front anyway
Expand Down
Loading