Commit 0fda1d46 authored by Jeremy Tan's avatar Jeremy Tan

gstdio: simplify _g_win32_get_mode_alias

Do an in-place update on the wide-character mode string
parent 04dcee18
Pipeline #89886 passed with stages
in 24 minutes and 10 seconds
......@@ -139,6 +139,26 @@ w32_error_to_errno (DWORD error_code)
#include "gstdio-private.c"
/* Windows implementation of fopen() does not accept modes such as
* "wb+". The 'b' needs to be appended to "w+", i.e. "w+b". Note
* that otherwise these 2 modes are supposed to be aliases, hence
* swappable at will. TODO: Is this still true?
*/
static void
_g_win32_fix_mode (wchar_t *mode)
{
wchar_t *ptr;
wchar_t temp;
ptr = wcschr (mode, L'+');
if (ptr != NULL && (ptr - mode) > 1)
{
temp = mode[1];
mode[1] = *ptr;
*ptr = temp;
}
}
/* From
* https://support.microsoft.com/en-ca/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime
* FT = UT * 10000000 + 116444736000000000.
......@@ -778,26 +798,6 @@ g_win32_fstat (int fd,
return _g_win32_stat_fd (fd, buf);
}
static gchar *
_g_win32_get_mode_alias (const gchar *mode)
{
gchar *alias;
alias = g_strdup (mode);
if (strlen (mode) > 2 && mode[2] == '+')
{
/* Windows implementation of fopen() does not accept modes such as
* "wb+". The 'b' needs to be appended to "w+", i.e. "w+b". Note
* that otherwise these 2 modes are supposed to be aliases, hence
* swappable at will.
*/
alias[1] = '+';
alias[2] = mode[1];
}
return alias;
}
/**
* g_win32_readlink_utf8:
* @filename: (type filename): a pathname in UTF-8
......@@ -1552,7 +1552,6 @@ g_fopen (const gchar *filename,
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
wchar_t *wmode;
gchar *mode2;
FILE *retval;
int save_errno;
......@@ -1562,9 +1561,7 @@ g_fopen (const gchar *filename,
return NULL;
}
mode2 = _g_win32_get_mode_alias (mode);
wmode = g_utf8_to_utf16 (mode2, -1, NULL, NULL, NULL);
g_free (mode2);
wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
if (wmode == NULL)
{
......@@ -1573,6 +1570,7 @@ g_fopen (const gchar *filename,
return NULL;
}
_g_win32_fix_mode (wmode);
retval = _wfopen (wfilename, wmode);
save_errno = errno;
......@@ -1611,7 +1609,6 @@ g_freopen (const gchar *filename,
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
wchar_t *wmode;
gchar *mode2;
FILE *retval;
int save_errno;
......@@ -1621,9 +1618,7 @@ g_freopen (const gchar *filename,
return NULL;
}
mode2 = _g_win32_get_mode_alias (mode);
wmode = g_utf8_to_utf16 (mode2, -1, NULL, NULL, NULL);
g_free (mode2);
wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
if (wmode == NULL)
{
......@@ -1631,7 +1626,8 @@ g_freopen (const gchar *filename,
errno = EINVAL;
return NULL;
}
_g_win32_fix_mode (wmode);
retval = _wfreopen (wfilename, wmode, stream);
save_errno = errno;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment