aboutsummaryrefslogtreecommitdiffstats
path: root/common/exechelp.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common/exechelp.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/common/exechelp.c b/common/exechelp.c
index 4ec481f99..7da7dbd50 100644
--- a/common/exechelp.c
+++ b/common/exechelp.c
@@ -270,6 +270,50 @@ do_exec (const char *pgmname, const char *argv[],
#endif /*!HAVE_W32_SYSTEM*/
+/* Portable function to create a pipe. Under Windows the write end is
+ inheritable. */
+gpg_error_t
+gnupg_create_inbound_pipe (int filedes[2])
+{
+ gpg_error_t err = 0;
+#if HAVE_W32_SYSTEM
+ int fds[2];
+
+ filedes[0] = filedes[1] = -1;
+ err = gpg_error (GPG_ERR_GENERAL);
+ if (!create_inheritable_pipe (fds))
+ {
+ filedes[0] = _open_osfhandle (fds[0], 0);
+ if (filedes[0] == -1)
+ {
+ log_error ("failed to translate osfhandle %p\n", (void*)fds[0]);
+ CloseHandle (fd_to_handle (fds[1]));
+ }
+ else
+ {
+ filedes[1] = _open_osfhandle (fds[1], 1);
+ if (filedes[1] == -1)
+ {
+ log_error ("failed to translate osfhandle %p\n", (void*)fds[1]);
+ close (filedes[0]);
+ filedes[0] = -1;
+ CloseHandle (fd_to_handle (fds[1]));
+ }
+ else
+ err = 0;
+ }
+ }
+#else
+ if (pipe (filedes) == -1)
+ {
+ err = gpg_error_from_syserror ();
+ filedes[0] = filedes[1] = -1;
+ }
+#endif
+ return err;
+}
+
+
/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to
stdin, write the output to OUTFILE, return a new stream in
STATUSFILE for stderr and the pid of the process in PID. The