From dcf4cef02f26d2559dfabfa7e22a11bd0a26664b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Tue, 31 Oct 2023 12:54:51 +0100
Subject: [PATCH] Add missing <unistd.h> includes for Python 3.13+
 compatibility

According to https://docs.python.org/3.13/whatsnew/3.13.html:

> Python.h no longer includes the <unistd.h> standard header file.
> If needed, it should now be included explicitly.
> For example, it provides the functions: read(), write(), close(),
> isatty(), lseek(), getpid(), getcwd(), sysconf() and getpagesize().
> (Contributed by Victor Stinner in
> https://github.com/python/cpython/issues/108765)

The build failures with -Werror=implicit-function-declaration were:

    .../dbus_bindings/unixfd.c: In function 'UnixFd_tp_new':
    .../dbus_bindings/unixfd.c:146:10: error: implicit declaration of function 'dup' [-Werror=implicit-function-declaration]
      146 |     fd = dup(fd_original);
          |          ^~~
    .../dbus_bindings/unixfd.c:146:10: warning: nested extern declaration of 'dup' [-Wnested-externs]
    .../dbus_bindings/unixfd.c:154:9: error: implicit declaration of function 'close'; did you mean 'clone'? [-Werror=implicit-function-declaration]
      154 |         close(fd);
          |         ^~~~~
          |         clone

[smcv: Adjust include order, don't include unistd.h on Windows]
Co-authored-by: Simon McVittie <smcv@collabora.com>
---
 dbus_bindings/message-get-args.c | 4 ++++
 dbus_bindings/unixfd.c           | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/dbus_bindings/message-get-args.c b/dbus_bindings/message-get-args.c
index 628a616..af6fa84 100644
--- a/dbus_bindings/message-get-args.c
+++ b/dbus_bindings/message-get-args.c
@@ -28,6 +28,10 @@
 
 #include "dbus_bindings-internal.h"
 
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
 #define DBG_IS_TOO_VERBOSE
 #include "compat-internal.h"
 #include "types-internal.h"
diff --git a/dbus_bindings/unixfd.c b/dbus_bindings/unixfd.c
index e515cd3..4638c85 100644
--- a/dbus_bindings/unixfd.c
+++ b/dbus_bindings/unixfd.c
@@ -31,6 +31,10 @@
 #include <Python.h>
 #include <structmember.h>
 
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
 #include "types-internal.h"
 
 PyDoc_STRVAR(UnixFd_tp_doc,
-- 
GitLab