[glib: 1/11] gio: add GUnixFDList on win32
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/11] gio: add GUnixFDList on win32
- Date: Wed, 18 May 2022 14:01:44 +0000 (UTC)
commit 5efb84f24a83ba10f6e1ae0385fa0fbc68103ad1
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Thu Apr 7 17:59:00 2022 +0400
gio: add GUnixFDList on win32
FDs are not specific to Unix. win32 has APIs to map CRT fd to/from HANDLE.
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
gio/gio.h | 1 +
gio/gunixfdlist.c | 25 +++++++++++++++++++------
gio/meson.build | 2 +-
3 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/gio/gio.h b/gio/gio.h
index e37b6bb49f..6f92f8a660 100644
--- a/gio/gio.h
+++ b/gio/gio.h
@@ -169,6 +169,7 @@
#include <gio/gtlsserverconnection.h>
#include <gio/gunixconnection.h>
#include <gio/gunixcredentialsmessage.h>
+#include <gio/gunixfdlist.h>
#include <gio/gunixsocketaddress.h>
#include <gio/gvfs.h>
#include <gio/gvolume.h>
diff --git a/gio/gunixfdlist.c b/gio/gunixfdlist.c
index e8c4ac55e4..6689a72169 100644
--- a/gio/gunixfdlist.c
+++ b/gio/gunixfdlist.c
@@ -26,9 +26,11 @@
* the %G_SOCKET_FAMILY_UNIX family by using g_socket_send_message()
* and received using g_socket_receive_message().
*
- * Note that `<gio/gunixfdlist.h>` belongs to the UNIX-specific GIO
- * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
- * file when using it.
+ * Before 2.74, `<gio/gunixfdlist.h>` belonged to the UNIX-specific GIO
+ * interfaces, thus you had to use the `gio-unix-2.0.pc` pkg-config file when
+ * using it.
+ *
+ * Since 2.74, the API is available for Windows.
*/
/**
@@ -40,7 +42,6 @@
#include "config.h"
-#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
@@ -48,6 +49,12 @@
#include "gunixfdlist.h"
#include "gnetworking.h"
#include "gioerror.h"
+#include "glib/glib-private.h"
+#include "glib/gstdio.h"
+
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
struct _GUnixFDListPrivate
{
@@ -70,7 +77,7 @@ g_unix_fd_list_finalize (GObject *object)
gint i;
for (i = 0; i < list->priv->nfd; i++)
- close (list->priv->fds[i]);
+ g_close (list->priv->fds[i], NULL);
g_free (list->priv->fds);
G_OBJECT_CLASS (g_unix_fd_list_parent_class)
@@ -90,7 +97,9 @@ dup_close_on_exec_fd (gint fd,
GError **error)
{
gint new_fd;
+#ifndef G_OS_WIN32
gint s;
+#endif
#ifdef F_DUPFD_CLOEXEC
do
@@ -118,6 +127,9 @@ dup_close_on_exec_fd (gint fd,
return -1;
}
+#ifdef G_OS_WIN32
+ new_fd = GLIB_PRIVATE_CALL (g_win32_reopen_noninherited) (new_fd, 0, error);
+#else
do
{
s = fcntl (new_fd, F_GETFD);
@@ -134,10 +146,11 @@ dup_close_on_exec_fd (gint fd,
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (saved_errno),
"fcntl: %s", g_strerror (saved_errno));
- close (new_fd);
+ g_close (new_fd, NULL);
return -1;
}
+#endif
return new_fd;
}
diff --git a/gio/meson.build b/gio/meson.build
index e980ad9e48..2d20794e46 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -354,7 +354,6 @@ if host_system != 'windows'
unix_sources = files(
'gfiledescriptorbased.c',
'giounix-private.c',
- 'gunixfdlist.c',
'gunixfdmessage.c',
'gunixmount.c',
'gunixmounts.c',
@@ -574,6 +573,7 @@ gio_sources = files(
'gdtlsserverconnection.c',
'gunionvolumemonitor.c',
'gunixconnection.c',
+ 'gunixfdlist.c',
'gunixcredentialsmessage.c',
'gunixsocketaddress.c',
'gvfs.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]