mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 19:36:18 +01:00
Merge branch 'win32-gstdio-minor' into 'master'
gstdio: minor cleanups See merge request GNOME/glib!939
This commit is contained in:
commit
91c1f33bb4
@ -102,22 +102,35 @@ w32_error_to_errno (DWORD error_code)
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return EACCES;
|
||||
break;
|
||||
case ERROR_INVALID_HANDLE:
|
||||
return EBADF;
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
case ERROR_FILE_EXISTS:
|
||||
return EEXIST;
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
return ENOENT;
|
||||
break;
|
||||
case ERROR_INVALID_FUNCTION:
|
||||
return EFAULT;
|
||||
break;
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
return ENOENT;
|
||||
case ERROR_INVALID_HANDLE:
|
||||
return EBADF;
|
||||
break;
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
return ENOENT; /* or ELOOP, or ENAMETOOLONG */
|
||||
case ERROR_INVALID_PARAMETER:
|
||||
return EINVAL;
|
||||
break;
|
||||
case ERROR_LOCK_VIOLATION:
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
return EACCES;
|
||||
break;
|
||||
case ERROR_NOT_ENOUGH_MEMORY:
|
||||
case ERROR_OUTOFMEMORY:
|
||||
return ENOMEM;
|
||||
break;
|
||||
case ERROR_NOT_SAME_DEVICE:
|
||||
return EXDEV;
|
||||
break;
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
return ENOENT; /* or ELOOP, or ENAMETOOLONG */
|
||||
break;
|
||||
default:
|
||||
return EIO;
|
||||
break;
|
||||
@ -126,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.
|
||||
@ -765,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
|
||||
@ -1154,20 +1167,7 @@ g_rename (const gchar *oldfilename,
|
||||
else
|
||||
{
|
||||
retval = -1;
|
||||
switch (GetLastError ())
|
||||
{
|
||||
#define CASE(a,b) case ERROR_##a: save_errno = b; break
|
||||
CASE (FILE_NOT_FOUND, ENOENT);
|
||||
CASE (PATH_NOT_FOUND, ENOENT);
|
||||
CASE (ACCESS_DENIED, EACCES);
|
||||
CASE (NOT_SAME_DEVICE, EXDEV);
|
||||
CASE (LOCK_VIOLATION, EACCES);
|
||||
CASE (SHARING_VIOLATION, EACCES);
|
||||
CASE (FILE_EXISTS, EEXIST);
|
||||
CASE (ALREADY_EXISTS, EEXIST);
|
||||
#undef CASE
|
||||
default: save_errno = EIO;
|
||||
}
|
||||
save_errno = w32_error_to_errno (GetLastError ());
|
||||
}
|
||||
|
||||
g_free (woldfilename);
|
||||
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user