aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2019-07-24 05:04:56 +0000
committerNIIBE Yutaka <[email protected]>2019-07-24 05:04:56 +0000
commit655ed9d83889bbb61d4b96755a2bd676622064c8 (patch)
tree71d4596e3dfef27396b1e00e508ef9d7338d72c4
parentbuild: Use {CFLAGS,CPPFLAGS, LDFLAGS}_FOR_BUILD for helper programs (diff)
downloadlibgpg-error-655ed9d83889bbb61d4b96755a2bd676622064c8.tar.gz
libgpg-error-655ed9d83889bbb61d4b96755a2bd676622064c8.zip
w32: Fix HANDLE to internal fd conversion.
* src/spawn-w32.c (handle_to_fd): Use intptr_t type. -- See the section of _open_osfhandle in C Run-Time Library Reference. Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r--src/spawn-w32.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/spawn-w32.c b/src/spawn-w32.c
index 91f9ac4..12ebe40 100644
--- a/src/spawn-w32.c
+++ b/src/spawn-w32.c
@@ -54,14 +54,29 @@
#undef X_OK
#define X_OK F_OK
-/* We assume that a HANDLE can be represented by an int which should
- * be true for all i386 systems (HANDLE is defined as void *) and
- * these are the only systems for which Windows is available. Further
- * we assume that -1 denotes an invalid handle.
- * FIXME: With Windows 64 this is no longer true.
+/* For HANDLE and the internal file descriptor (fd) of this module:
+ * HANDLE can be represented by an intptr_t which should be true for
+ * all systems (HANDLE is defined as void *). Further, we assume that
+ * -1 denotes an invalid handle.
+ *
+ * Note that a C run-time file descriptor (the exposed one to API) is
+ * always represented by an int.
*/
#define fd_to_handle(a) ((HANDLE)(a))
-#define handle_to_fd(a) ((int)(a))
+#define handle_to_fd(a) ((intptr_t)(a))
+
+/* For pid_t and HANDLE:
+
+ * We assume that a HANDLE can be represented by an int which should
+ * be true for all i386 systems.
+ *
+ * On 64-bit machine, it is no longer true, as a type, however, as
+ * long as the range of the value in the type HANDLE can be
+ * represented by an int, it works.
+ *
+ * FIXME: Breaking ABI for pid_t will be needed when the value won't
+ * fit within 32-bit range on 64-bit machine.
+ */
#define pid_to_handle(a) ((HANDLE)(a))
#define handle_to_pid(a) ((int)(a))