From 2abea42d9ce482d5d7eb4e6ecaa2ae798ba519a1 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 6 Jul 2023 10:25:15 +0900 Subject: [PATCH] kbx: Use es_sysopen_nc instead of es_fdopen_nc. * kbx/kbxserver.c (prepare_outstream): Use es_sysopen_nc and avoid the use of translate_sys2libc_fd. -- On Windows, it's better directly use the system HANDLE. Signed-off-by: NIIBE Yutaka --- kbx/kbxserver.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/kbx/kbxserver.c b/kbx/kbxserver.c index ae9ae5c75..cc122fad5 100644 --- a/kbx/kbxserver.c +++ b/kbx/kbxserver.c @@ -131,21 +131,34 @@ get_assuan_ctx_from_ctrl (ctrl_t ctrl) static gpg_error_t prepare_outstream (ctrl_t ctrl) { - int fd; + gnupg_fd_t fd; + estream_t out_fp = NULL; log_assert (ctrl && ctrl->server_local); if (ctrl->server_local->outstream) return 0; /* Already enabled. */ - fd = translate_sys2libc_fd - (assuan_get_output_fd (get_assuan_ctx_from_ctrl (ctrl)), 1); - if (fd == -1) + fd = assuan_get_output_fd (get_assuan_ctx_from_ctrl (ctrl)); + if (fd == GNUPG_INVALID_FD) return 0; /* No Output command active. */ + else + { + es_syshd_t syshd; - ctrl->server_local->outstream = es_fdopen_nc (fd, "w"); - if (!ctrl->server_local->outstream) - return gpg_err_code_from_syserror (); +#ifdef HAVE_W32_SYSTEM + syshd.type = ES_SYSHD_HANDLE; + syshd.u.handle = fd; +#else + syshd.type = ES_SYSHD_FD; + syshd.u.fd = fd; +#endif + out_fp = es_sysopen_nc (&syshd, "w"); + if (!out_fp) + return gpg_err_code_from_syserror (); + } + + ctrl->server_local->outstream = out_fp; return 0; }