If the input file path contains ANSI-encoded special characters,

utf-8 conversion and thus file opening will fail.

This patch then in addition tries opening the file with standard fopen.
This commit is contained in:
Holger Vogt 2021-04-17 18:19:39 +02:00
parent ba262eaa5f
commit d2f6ad239f
1 changed files with 10 additions and 1 deletions

View File

@ -266,6 +266,7 @@ ngdirname(const char *name)
FILE *
newfopen(const char *fn, const char* md)
{
FILE* fp;
if (fn == NULL)
return NULL;
wchar_t wfn[BSIZE_SP];
@ -276,7 +277,15 @@ newfopen(const char *fn, const char* md)
fprintf(stderr, "%s could not be converted\n", fn);
return NULL;
}
return _wfopen(wfn, wmd);
fp = _wfopen(wfn, wmd);
/* If wide char fails, at least fopen may try the potentially ANSI encoded special characters like á */
#undef fopen
if (fp == NULL)
fp = fopen(fn, md);
#define fopen newfopen
return fp;
}
#endif
#endif