Skip to content

Commit

Permalink
HostFS: open file for write+ if it doesn't exist in modify mode (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur authored Nov 5, 2023
1 parent 04ad522 commit c224340
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ieee.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <direct.h>
// Windows just has to be different
#define localtime_r(S,D) !localtime_s(D,S)
#include <io.h>
#define F_OK 0
#define access _access
#endif

extern SDL_RWops *prg_file;
Expand Down Expand Up @@ -1560,7 +1563,11 @@ copen(int channel)
if (append) {
channels[channel].f = SDL_RWFromFile((char *)resolved_filename, "ab+");
} else if (channels[channel].read && channels[channel].write) {
channels[channel].f = SDL_RWFromFile((char *)resolved_filename, "rb+");
if (access((char *)resolved_filename, F_OK) == 0) {
channels[channel].f = SDL_RWFromFile((char *)resolved_filename, "rb+");
} else {
channels[channel].f = SDL_RWFromFile((char *)resolved_filename, "wb+");
}
} else {
channels[channel].f = SDL_RWFromFile((char *)resolved_filename, channels[channel].write ? "wb" : "rb");
}
Expand Down

0 comments on commit c224340

Please sign in to comment.