From f3def63fed8c6c1baf66aa5426d3e8c95b917762 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Sep 2021 15:27:46 +0200 Subject: [PATCH] std-aux: add nm_clear_fd() helper --- src/libnm-std-aux/nm-std-aux.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 6a1e1be4c9..df8a4c1836 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -845,6 +845,19 @@ nm_close(int fd) return r; } +static inline bool +nm_clear_fd(int *p_fd) +{ + int fd; + + if (!p_fd || (fd = *p_fd) < 0) + return false; + + *p_fd = -1; + nm_close(fd); + return true; +} + /*****************************************************************************/ /* Note: @value is only evaluated when *out_val is present.