From f2d829e3db0241fef527135c5d92540fa758f8dd Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 10 May 2023 13:55:39 +0900 Subject: w32: Fix pipeconnect test program for Windows. * tests/pipeconnect.c: Fix for input_fd and output_fd. -- Signed-off-by: NIIBE Yutaka --- tests/pipeconnect.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/pipeconnect.c b/tests/pipeconnect.c index f5abfb5..1ee4004 100644 --- a/tests/pipeconnect.c +++ b/tests/pipeconnect.c @@ -33,6 +33,9 @@ #include #include +#ifdef HAVE_W32_SYSTEM +#include +#endif #include "../src/assuan.h" #include "common.h" @@ -55,27 +58,43 @@ cmd_echo (assuan_context_t ctx, char *line) static gpg_error_t cmd_cat (assuan_context_t ctx, char *line) { - assuan_fd_t fd, fdout; + assuan_fd_t assuan_fdin, assuan_fdout; + int fd, fdout; int c; FILE *fp, *fpout; int nbytes; log_info ("got CAT command (%s)\n", line); +#ifdef HAVE_W32_SYSTEM + assuan_fdin = assuan_get_input_fd (ctx); + if (assuan_fdin == ASSUAN_INVALID_FD) + return gpg_error (GPG_ERR_ASS_NO_INPUT); + assuan_fdout = assuan_get_output_fd (ctx); + if (assuan_fdout == ASSUAN_INVALID_FD) + return gpg_error (GPG_ERR_ASS_NO_OUTPUT); + fd = _open_osfhandle ((intptr_t)assuan_fdin, _O_RDONLY); + if (fd < 0) + return gpg_error (GPG_ERR_ASS_NO_INPUT); + fdout = _open_osfhandle ((intptr_t)assuan_fdout, _O_WRONLY); + if (fdout < 0) + return gpg_error (GPG_ERR_ASS_NO_OUTPUT); +#else fd = assuan_get_input_fd (ctx); if (fd == ASSUAN_INVALID_FD) return gpg_error (GPG_ERR_ASS_NO_INPUT); fdout = assuan_get_output_fd (ctx); if (fdout == ASSUAN_INVALID_FD) return gpg_error (GPG_ERR_ASS_NO_OUTPUT); - fp = fdopen ((int)fd, "r"); +#endif + fp = fdopen (fd, "r"); if (!fp) { log_error ("fdopen failed on input fd: %s\n", strerror (errno)); return gpg_error (GPG_ERR_ASS_GENERAL); } - fpout = fdopen ((int)fdout, "w"); + fpout = fdopen (fdout, "w"); if (!fpout) { log_error ("fdopen failed on output fd: %s\n", strerror (errno)); -- cgit v1.2.1