1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-03 12:11:33 +01:00

common,w32: Extend gnupg_create_inbound_pipe et al.

* common/exechelp-w32.c (do_create_pipe): Rename, add arguments, and
create a stream if reqested.
(gnupg_create_inbound_pipe): Use the extended function to open the
stream if requested.
(gnupg_create_outbound_pipe): Likewise.
(gnupg_create_pipe): Update call site.

Fixes-commit: 5d991e333a1885adc40abd9d00c01fec4bd5d9d7
Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-10-18 13:55:12 +02:00
parent 727ca74bb9
commit f2d39a6d05

View File

@ -301,7 +301,8 @@ w32_open_null (int for_write)
static gpg_error_t static gpg_error_t
do_create_pipe (int filedes[2], int flags) create_pipe_and_estream (int filedes[2], int flags,
estream_t *r_fp, int outbound, int nonblock)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
HANDLE fds[2]; HANDLE fds[2];
@ -330,6 +331,25 @@ do_create_pipe (int filedes[2], int flags)
err = 0; err = 0;
} }
} }
if (! err && r_fp)
{
if (!outbound)
*r_fp = es_fdopen (filedes[0], nonblock? "r,nonblock" : "r");
else
*r_fp = es_fdopen (filedes[1], nonblock? "w,nonblock" : "w");
if (!*r_fp)
{
err = my_error_from_syserror ();
log_error (_("error creating a stream for a pipe: %s\n"),
gpg_strerror (err));
close (filedes[0]);
close (filedes[1]);
filedes[0] = filedes[1] = -1;
return err;
}
}
return err; return err;
} }
@ -339,10 +359,8 @@ do_create_pipe (int filedes[2], int flags)
gpg_error_t gpg_error_t
gnupg_create_inbound_pipe (int filedes[2], estream_t *r_fp, int nonblock) gnupg_create_inbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
{ {
if (r_fp) return create_pipe_and_estream (filedes, INHERIT_WRITE,
return gpg_error (GPG_ERR_NOT_IMPLEMENTED); r_fp, 0, nonblock);
else
return do_create_pipe (filedes, INHERIT_WRITE);
} }
@ -352,10 +370,8 @@ gnupg_create_inbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
gpg_error_t gpg_error_t
gnupg_create_outbound_pipe (int filedes[2], estream_t *r_fp, int nonblock) gnupg_create_outbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
{ {
if (r_fp) return create_pipe_and_estream (filedes, INHERIT_READ,
return gpg_error (GPG_ERR_NOT_IMPLEMENTED); r_fp, 1, nonblock);
else
return do_create_pipe (filedes, INHERIT_READ);
} }
@ -364,7 +380,8 @@ gnupg_create_outbound_pipe (int filedes[2], estream_t *r_fp, int nonblock)
gpg_error_t gpg_error_t
gnupg_create_pipe (int filedes[2]) gnupg_create_pipe (int filedes[2])
{ {
return do_create_pipe (filedes, INHERIT_BOTH); return create_pipe_and_estream (filedes, INHERIT_BOTH,
NULL, 0, 0);
} }