mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
common,gpg,kbx: Factor out open_stream_nc.
* common/sysutils.h (open_stream_nc): New. * common/sysutils.c (open_stream_nc): New. * g10/decrypt.c (decrypt_message_fd): Use open_stream_nc. * g10/server.c (cmd_verify): Likewise. * kbx/kbxserver.c (prepare_outstream): Likewise. -- GnuPG-bug-id: 6580 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
5bc949d230
commit
37343db08f
@ -1931,3 +1931,22 @@ gnupg_fd_valid (int fd)
|
||||
close (d);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Open a stream from FD (a file descriptor on POSIX, a system
|
||||
handle on Windows), non-closed. */
|
||||
estream_t
|
||||
open_stream_nc (gnupg_fd_t fd, const char *mode)
|
||||
{
|
||||
es_syshd_t syshd;
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
syshd.type = ES_SYSHD_HANDLE;
|
||||
syshd.u.handle = fd;
|
||||
#else
|
||||
syshd.type = ES_SYSHD_FD;
|
||||
syshd.u.fd = fd;
|
||||
#endif
|
||||
|
||||
return es_sysopen_nc (&syshd, mode);
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ gpg_error_t gnupg_inotify_watch_delete_self (int *r_fd, const char *fname);
|
||||
gpg_error_t gnupg_inotify_watch_socket (int *r_fd, const char *socket_name);
|
||||
int gnupg_inotify_has_name (int fd, const char *name);
|
||||
|
||||
estream_t open_stream_nc (gnupg_fd_t fd, const char *mode);
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
int gnupg_w32_set_errno (int ec);
|
||||
|
@ -114,7 +114,6 @@ decrypt_message_fd (ctrl_t ctrl, gnupg_fd_t input_fd,
|
||||
IOBUF fp;
|
||||
armor_filter_context_t *afx = NULL;
|
||||
progress_filter_context_t *pfx;
|
||||
es_syshd_t syshd;
|
||||
|
||||
if (opt.outfp)
|
||||
return gpg_error (GPG_ERR_BUG);
|
||||
@ -140,14 +139,7 @@ decrypt_message_fd (ctrl_t ctrl, gnupg_fd_t input_fd,
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
syshd.type = ES_SYSHD_HANDLE;
|
||||
syshd.u.handle = output_fd;
|
||||
#else
|
||||
syshd.type = ES_SYSHD_FD;
|
||||
syshd.u.fd = output_fd;
|
||||
#endif
|
||||
opt.outfp = es_sysopen_nc (&syshd, "w");
|
||||
opt.outfp = open_stream_nc (output_fd, "w");
|
||||
if (!opt.outfp)
|
||||
{
|
||||
char xname[64];
|
||||
|
11
g10/server.c
11
g10/server.c
@ -388,16 +388,7 @@ cmd_verify (assuan_context_t ctx, char *line)
|
||||
|
||||
if (out_fd != GNUPG_INVALID_FD)
|
||||
{
|
||||
es_syshd_t syshd;
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
syshd.type = ES_SYSHD_HANDLE;
|
||||
syshd.u.handle = out_fd;
|
||||
#else
|
||||
syshd.type = ES_SYSHD_FD;
|
||||
syshd.u.fd = out_fd;
|
||||
#endif
|
||||
out_fp = es_sysopen_nc (&syshd, "w");
|
||||
out_fp = open_stream_nc (fd, "w");
|
||||
if (!out_fp)
|
||||
return set_error (gpg_err_code_from_syserror (), "fdopen() failed");
|
||||
}
|
||||
|
@ -144,16 +144,7 @@ prepare_outstream (ctrl_t ctrl)
|
||||
return 0; /* No Output command active. */
|
||||
else
|
||||
{
|
||||
es_syshd_t syshd;
|
||||
|
||||
#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");
|
||||
out_fp = open_stream_nc (fd, "w");
|
||||
if (!out_fp)
|
||||
return gpg_err_code_from_syserror ();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user