Merge branch 'win32-fd' into 'main'

gio: various unix/fd-related enablement on win32

See merge request GNOME/glib!2656
This commit is contained in:
Philip Withnall
2022-05-18 14:01:43 +00:00
10 changed files with 224 additions and 109 deletions

View File

@@ -28,9 +28,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.
*/
/**
@@ -42,7 +44,6 @@
#include "config.h"
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
@@ -50,6 +51,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
{
@@ -72,7 +79,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)
@@ -92,7 +99,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
@@ -120,6 +129,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);
@@ -136,10 +148,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;
}