mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Fixed ANSI-C compatibility in lj_fopen.c
This commit is contained in:
parent
ee4a518ae1
commit
8f570d6355
@ -7,16 +7,18 @@
|
||||
|
||||
FILE *_lua_fopen(const char *filename, const char *mode)
|
||||
{
|
||||
int new_Len1 = 0;
|
||||
int new_Len2 = 0;
|
||||
int fn_len_s = strlen(filename);
|
||||
if(fn_len_s==0) return NULL;
|
||||
int m_len_s = strlen(mode);
|
||||
if(fn_len_s==0) return NULL;
|
||||
if(m_len_s==0) return NULL;
|
||||
wchar_t path[MAX_PATH];
|
||||
wchar_t wmode[MAX_PATH];
|
||||
int new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
|
||||
new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
|
||||
if(new_Len1>=MAX_PATH) return NULL;
|
||||
path[new_Len1] = L'\0';
|
||||
int new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
|
||||
new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
|
||||
if(new_Len2>=MAX_PATH) return NULL;
|
||||
wmode[new_Len2] = L'\0';
|
||||
FILE *f = _wfopen(path, wmode);
|
||||
@ -25,21 +27,21 @@ FILE *_lua_fopen(const char *filename, const char *mode)
|
||||
|
||||
FILE *_lua_freopen(const char *filename, const char *mode, FILE * oldfile)
|
||||
{
|
||||
int new_Len1 = 0;
|
||||
int new_Len2 = 0;
|
||||
int fn_len_s = strlen(filename);
|
||||
int m_len_s = strlen(mode);
|
||||
if(fn_len_s==0) return NULL;
|
||||
int m_len_s=strlen(filename);
|
||||
if(m_len_s==0) return NULL;
|
||||
wchar_t path[MAX_PATH];
|
||||
wchar_t wmode[MAX_PATH];
|
||||
int new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
|
||||
new_Len1 = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
|
||||
if(new_Len1>=MAX_PATH) return NULL;
|
||||
path[new_Len1] = L'\0';
|
||||
int new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
|
||||
new_Len2 = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
|
||||
if(new_Len2>=MAX_PATH) return NULL;
|
||||
wmode[new_Len2] = L'\0';
|
||||
FILE *f = _wfreopen(path, wmode, oldfile);
|
||||
LocalFree(path);
|
||||
LocalFree(wmode);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user