return NULL upon NULL input

This commit is contained in:
Holger Vogt 2019-12-22 22:21:27 +01:00
parent 68f95d4407
commit 52a65f0aac
1 changed files with 3 additions and 1 deletions

View File

@ -258,6 +258,7 @@ ngdirname(const char *name)
#endif
/* Replacement for fopen, when using wide chars (utf-16) */
#ifndef EXT_ASC
#if defined(__MINGW__) || defined(_MSC_VER)
#undef BOOLEAN
@ -265,10 +266,11 @@ ngdirname(const char *name)
FILE *
newfopen(char *fn, char* md)
{
if (fn == NULL)
return NULL;
wchar_t wfn[BSIZE_SP];
wchar_t wmd[16];
MultiByteToWideChar(CP_UTF8, 0, md, -1, wmd, 15);
MultiByteToWideChar(CP_UTF8, 0, fn, -1, wfn, BSIZE_SP - 1);
if (MultiByteToWideChar(CP_UTF8, 0, fn, -1, wfn, BSIZE_SP - 1) == 0) {
fprintf(stderr, "UTF-8 to UTF-16 conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", fn);