Skip to content

Commit

Permalink
Remove Unicode paths code again
Browse files Browse the repository at this point in the history
Still not working.
  • Loading branch information
bradharding committed Aug 27, 2022
1 parent 3553b21 commit 6ae94c4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 127 deletions.
107 changes: 0 additions & 107 deletions src/w_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,113 +45,6 @@
#include "w_file.h"
#include "z_zone.h"

#if defined(_WIN32)
static wchar_t *ConvertUTF8ToWide(const char *str)
{
const int wlen = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
wchar_t *wstr = (wchar_t *)malloc(wlen * sizeof(wchar_t));

if (!wstr)
return NULL;

if (!MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, wlen))
{
free(wstr);
return NULL;
}

return wstr;
}

FILE *D_fopen(const char *filename, const char *mode)
{
wchar_t *wname = ConvertUTF8ToWide(filename);
wchar_t *wmode;
FILE *file;

if (!wname)
return NULL;

if (!(wmode = ConvertUTF8ToWide(mode)))
{
free(wname);
return NULL;
}

file = _wfopen(wname, wmode);
free(wname);
free(wmode);

return file;
}

int D_remove(const char *path)
{
wchar_t *wpath = ConvertUTF8ToWide(path);
int result;

if (!wpath)
return 0;

result = _wremove(wpath);
free(wpath);

return result;
}

int D_rename(const char *oldname, const char *newname)
{
wchar_t *wold = ConvertUTF8ToWide(oldname);
wchar_t *wnew;
int result;

if (!wold)
return 0;

if (!(wnew = ConvertUTF8ToWide(newname)))
{
free(wold);
return 0;
}

result = _wrename(wold, wnew);
free(wold);
free(wnew);

return result;
}

int D_stat(const char *path, struct stat *buffer)
{
wchar_t *wpath = ConvertUTF8ToWide(path);
struct _stat wbuffer;
int result;

if (!wpath)
return -1;

result = _wstat(wpath, &wbuffer);
buffer->st_mode = wbuffer.st_mode;
free(wpath);

return result;
}

int D_mkdir(const char *dirname)
{
wchar_t *wpath = ConvertUTF8ToWide(dirname);
int result;

if (!wpath)
return 0;

result = _wmkdir(wpath);
free(wpath);

return result;
}
#endif

wadfile_t *W_OpenFile(char *path)
{
wadfile_t *result;
Expand Down
20 changes: 0 additions & 20 deletions src/w_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@
#define MAX_PATH 260
#endif

#if defined(_WIN32)
FILE *D_fopen(const char *filename, const char *mode);
int D_remove(const char *path);
int D_rename(const char *oldname, const char *newname);
int D_stat(const char *path, struct stat *buffer);
int D_mkdir(const char *dirname);

#undef fopen
#undef remove
#undef rename
#undef stat
#undef mkdir

#define fopen(filename, mode) D_fopen(filename, mode)
#define remove(path) D_remove(path)
#define rename(oldname, newname) D_rename(oldname, newname)
#define stat(path, buffer) D_stat(path, buffer)
#define mkdir(dirname) D_mkdir(dirname)
#endif

typedef struct
{
FILE *fstream;
Expand Down

0 comments on commit 6ae94c4

Please sign in to comment.