diff options
author | NIIBE Yutaka <[email protected]> | 2023-07-07 06:07:34 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2023-07-10 02:22:43 +0000 |
commit | 37343db08f4aaa36a0f58d2ecf50e7fbba4cacd7 (patch) | |
tree | be0f1034812739c231bd3871ceeb36ca8a4009cf | |
parent | common:w32: Fix gnupg_w32_set_errno. (diff) | |
download | gnupg-37343db08f4aaa36a0f58d2ecf50e7fbba4cacd7.tar.gz gnupg-37343db08f4aaa36a0f58d2ecf50e7fbba4cacd7.zip |
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 <[email protected]>
-rw-r--r-- | common/sysutils.c | 19 | ||||
-rw-r--r-- | common/sysutils.h | 1 | ||||
-rw-r--r-- | g10/decrypt.c | 10 | ||||
-rw-r--r-- | g10/server.c | 11 | ||||
-rw-r--r-- | kbx/kbxserver.c | 11 |
5 files changed, 23 insertions, 29 deletions
diff --git a/common/sysutils.c b/common/sysutils.c index 73690a760..745b762ba 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -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); +} diff --git a/common/sysutils.h b/common/sysutils.h index 50e59175f..8cc303b61 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -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); diff --git a/g10/decrypt.c b/g10/decrypt.c index e000ac478..64ba0b7f1 100644 --- a/g10/decrypt.c +++ b/g10/decrypt.c @@ -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]; diff --git a/g10/server.c b/g10/server.c index 8ddfbba8e..24e525e7f 100644 --- a/g10/server.c +++ b/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"); } diff --git a/kbx/kbxserver.c b/kbx/kbxserver.c index cc122fad5..d50b9dfdf 100644 --- a/kbx/kbxserver.c +++ b/kbx/kbxserver.c @@ -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 (); } |