From 2042f5a4641f4e43137b7683077b4d733d216417 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 2 Sep 2020 14:49:24 +0200 Subject: [PATCH] common: New helper function gnupg_close_pipe. * common/exechelp-posix.c (gnupg_close_pipe): New. * common/exechelp-w32.c (gnupg_close_pipe): New. -- This function is mainly for documentation purposes and should be used along with gnupg_create_pipe. Signed-off-by: Werner Koch --- common/exechelp-posix.c | 9 +++++++++ common/exechelp-w32.c | 9 +++++++++ common/exechelp.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index 425f2b4d5..2b724ce5f 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -416,6 +416,15 @@ gnupg_create_pipe (int filedes[2]) } +/* Close the end of a pipe. */ +void +gnupg_close_pipe (int fd) +{ + if (fd != -1) + close (fd); +} + + /* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c index ea158a33f..be684caaa 100644 --- a/common/exechelp-w32.c +++ b/common/exechelp-w32.c @@ -397,6 +397,15 @@ gnupg_create_pipe (int filedes[2]) } +/* Close the end of a pipe. */ +void +gnupg_close_pipe (int fd) +{ + if (fd != -1) + close (fd); +} + + /* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], diff --git a/common/exechelp.h b/common/exechelp.h index 9e1f56f70..d50e378e7 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -69,6 +69,9 @@ gpg_error_t gnupg_create_outbound_pipe (int filedes[2], inheritable. */ gpg_error_t gnupg_create_pipe (int filedes[2]); +/* Close the end of a pipe. */ +void gnupg_close_pipe (int fd); + #define GNUPG_SPAWN_NONBLOCK 16 #define GNUPG_SPAWN_RUN_ASFW 64