Add log messages to fluid_fopen()

This commit is contained in:
derselbst 2020-12-22 10:54:31 +01:00
parent 1cdeebef37
commit ed34742824

View file

@ -225,43 +225,46 @@ void* fluid_alloc(size_t len)
FILE *fluid_fopen(const char *filename, const char *mode)
{
#if defined(WIN32)
wchar_t *wpath, *wmode;
FILE *file;
wchar_t *wpath = NULL, *wmode = NULL;
FILE *file = NULL;
int length;
if ((length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, NULL, 0)) == 0)
{
FLUID_LOG(FLUID_ERR, "Unable to perform MultiByteToWideChar() conversion for filename '%s'. Error was: '%s'", filename, fluid_get_windows_error());
errno = EINVAL;
return NULL;
goto error_recovery;
}
wpath = FLUID_MALLOC(length * sizeof(wchar_t));
if (wpath == NULL)
{
FLUID_LOG(FLUID_PANIC, "Out of memory.");
errno = EINVAL;
return NULL;
goto error_recovery;
}
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wpath, length);
if ((length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, NULL, 0)) == 0)
{
FLUID_FREE(wpath);
FLUID_LOG(FLUID_ERR, "Unable to perform MultiByteToWideChar() conversion for mode '%s'. Error was: '%s'", mode, fluid_get_windows_error());
errno = EINVAL;
return NULL;
goto error_recovery;
}
wmode = FLUID_MALLOC(length * sizeof(wchar_t));
if (wmode == NULL)
{
FLUID_FREE(wpath);
FLUID_LOG(FLUID_PANIC, "Out of memory.");
errno = EINVAL;
return NULL;
goto error_recovery;
}
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, length);
file = _wfopen(wpath, wmode);
error_recovery:
FLUID_FREE(wpath);
FLUID_FREE(wmode);