summarylogtreecommitdiffstats
path: root/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch
diff options
context:
space:
mode:
Diffstat (limited to '0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch')
-rw-r--r--0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch124
1 files changed, 73 insertions, 51 deletions
diff --git a/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch b/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch
index e53fd8d166f9..c3c4c756638b 100644
--- a/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch
+++ b/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch
@@ -1,7 +1,28 @@
-diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
---- glib-2.46.0-orig/glib/gstdio.c 2015-02-26 15:57:09.000000000 +0300
-+++ glib-2.46.0/glib/gstdio.c 2015-09-22 09:08:58.032066100 +0300
-@@ -192,6 +192,11 @@
+From 7f4f4354540440c0a8a37beaccbec8bc7fc15ec7 Mon Sep 17 00:00:00 2001
+From: Erik van Pienbroek <epienbro@fedoraproject.org>
+Date: Mon, 27 Aug 2012 23:28:54 +0200
+Subject: [PATCH] Use CreateFile on Win32 to make sure g_unlink always works
+
+The functions g_open(), g_creat() and g_fopen() defer to _wopen(),
+_wcreat() and _wfopen() respectively. This is very similar to
+the corresponding arrangement for Linux. However, those Windows
+functions do not support renaming a file whilst it's open. As a
+result, g_rename() behaves differently on the Windows platform
+compared to its Linux behaviour, where files can be renamed even
+while there are file handles still open. Resolved this by using
+the Win32 API function CreateFile() instead of _wopen(), _wcreat()
+and _wfopen()
+
+Patch initially created by John Emmas
+---
+ glib/gstdio.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
+ 1 file changed, 233 insertions(+), 26 deletions(-)
+
+diff --git a/glib/gstdio.c b/glib/gstdio.c
+index 6d763e1..c1d072f 100644
+--- a/glib/gstdio.c
++++ b/glib/gstdio.c
+@@ -758,6 +758,11 @@
int mode)
{
#ifdef G_OS_WIN32
@@ -9,11 +30,11 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ DWORD dwDesiredAccess = 0;
+ DWORD dwFlagsAndAttributes = 0;
+ DWORD dwDisposition = OPEN_EXISTING;
-+ DWORD dwSharedAccess = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
++ DWORD dwSharedAccess = FILE_SHARE_READ | FILE_SHARE_DELETE;
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
-@@ -202,12 +207,114 @@
+@@ -768,12 +773,114 @@
return -1;
}
@@ -29,45 +50,45 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ {
+ /* Equates to _O_RDONLY */
+ if (flags & _O_TRUNC)
-+ {
-+ errno = EINVAL;
-+ g_free (wfilename);
-+ return -1;
-+ }
++ {
++ errno = EINVAL;
++ g_free (wfilename);
++ return -1;
++ }
- g_free (wfilename);
-+ dwDesiredAccess |= GENERIC_READ;
-+ dwSharedAccess |= FILE_SHARE_WRITE;
++ dwDesiredAccess |= GENERIC_READ;
++ dwSharedAccess |= FILE_SHARE_WRITE;
+ }
+ if (flags & _O_WRONLY)
+ {
+ if (flags & _O_RDWR)
-+ {
-+ errno = EINVAL;
-+ g_free (wfilename);
-+ return -1;
-+ }
-
-+ dwDesiredAccess |= GENERIC_WRITE;
++ {
++ errno = EINVAL;
++ g_free (wfilename);
++ return -1;
++ }
++
++ dwDesiredAccess |= GENERIC_WRITE;
+ }
+ if (flags & _O_RDWR)
+ {
-+ dwDesiredAccess |= GENERIC_READ;
-+ dwDesiredAccess |= GENERIC_WRITE;
++ dwDesiredAccess |= GENERIC_READ;
++ dwDesiredAccess |= GENERIC_WRITE;
+ }
+ if (flags & _O_TRUNC)
+ {
+ if (flags & _O_CREAT)
-+ dwDisposition = CREATE_ALWAYS;
-+ else
-+ dwDisposition = TRUNCATE_EXISTING;
++ dwDisposition = CREATE_ALWAYS;
++ else
++ dwDisposition = TRUNCATE_EXISTING;
+ }
+ if ((flags & _O_CREAT) && !(flags & _O_TRUNC))
+ {
+ if (flags & _O_EXCL)
-+ dwDisposition = CREATE_NEW;
-+ else
-+ dwDisposition = OPEN_ALWAYS;
++ dwDisposition = CREATE_NEW;
++ else
++ dwDisposition = OPEN_ALWAYS;
+ }
+ if (flags & _O_CREAT)
+ {
@@ -112,7 +133,7 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ }
+ else
+ retval = _open_osfhandle((long)hFile, flags);
-+
+
+ if ((-1) != retval)
+ {
+ /* We have a valid file handle. Set its translation mode to text or binary, as appropriate */
@@ -131,7 +152,7 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
return retval;
#else
int fd;
-@@ -254,6 +361,8 @@
+@@ -821,6 +928,8 @@
int mode)
{
#ifdef G_OS_WIN32
@@ -140,7 +161,7 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
-@@ -264,12 +373,41 @@
+@@ -831,12 +940,41 @@
return -1;
}
@@ -185,12 +206,13 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
return retval;
#else
return creat (filename, mode);
-@@ -702,33 +840,102 @@
+@@ -1286,36 +1424,102 @@
const gchar *mode)
{
#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;
-
@@ -200,7 +222,9 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
- return NULL;
- }
-
-- wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
+- mode2 = _g_win32_get_mode_alias (mode);
+- wmode = g_utf8_to_utf16 (mode2, -1, NULL, NULL, NULL);
+- g_free (mode2);
-
- if (wmode == NULL)
- {
@@ -208,12 +232,6 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
- errno = EINVAL;
- return NULL;
- }
--
-- retval = _wfopen (wfilename, wmode);
-- save_errno = errno;
--
-- g_free (wfilename);
-- g_free (wmode);
+ int hFile;
+ int flags = 0;
+ gchar priv_mode[4];
@@ -226,7 +244,7 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ }
+ if ((strlen(mode) < 1) || (strlen(mode) > 3))
+ {
-+ errno = EINVAL;
++ errno - EINVAL;
+ goto out;
+ }
+
@@ -253,10 +271,10 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ else if (0 == strcmp(priv_mode, "w+t"))
+ flags = _O_RDWR | _O_CREAT |_O_TRUNC | _O_TEXT;
+ else
-+ {
-+ errno = EINVAL;
++ {
++ errno = EINVAL;
+ goto out;
-+ }
++ }
+ }
+ }
+ if (2 == strlen(priv_mode))
@@ -280,10 +298,10 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ else if (0 == strcmp(priv_mode, "wt"))
+ flags = _O_WRONLY | _O_CREAT | _O_TRUNC | _O_TEXT;
+ else
-+ {
-+ errno = EINVAL;
++ {
++ errno = EINVAL;
+ goto out;
-+ }
++ }
+ }
+ }
+ if (1 == strlen(priv_mode))
@@ -295,14 +313,18 @@ diff -Naur glib-2.46.0-orig/glib/gstdio.c glib-2.46.0/glib/gstdio.c
+ else if (0 == strcmp(priv_mode, "w"))
+ flags = _O_WRONLY | _O_CREAT | _O_TRUNC;
+ else if ( !((0 == strcmp(priv_mode, "c")) || (0 == strcmp(priv_mode, "n"))))
-+ {
-+ errno = EINVAL;
++ {
++ errno = EINVAL;
+ goto out;
-+ }
++ }
+ }
-+
+
+- retval = _wfopen (wfilename, wmode);
+- save_errno = errno;
+ hFile = g_open (filename, flags, (_S_IREAD | _S_IWRITE));
-+
+
+- g_free (wfilename);
+- g_free (wmode);
+ if (INVALID_HANDLE_VALUE == (HANDLE)hFile)
+ /* 'errno' will have already been set by 'g_open()' */
+ retval = NULL;