From: Adrian Vovk Date: Thu, 11 Jan 2024 20:43:05 +0000 (-0500) Subject: fd-util: Close function for FD_TO_PTR X-Git-Tag: v256-rc1~1089^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1bdae3645ae7336b6d440f150b987d246ce5d8d;p=thirdparty%2Fsystemd.git fd-util: Close function for FD_TO_PTR Just a function to be used as a destructor (i.e. in a _cleanup_ attribute, hash table operations, etc.) that closes an fd wrapped in FD_TO_PTR It just retrieves the fd via PTR_TO_FD and closes it --- diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 6a1143b4f30..183266513ac 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -52,6 +52,11 @@ static inline void fclosep(FILE **f) { safe_fclose(*f); } +static inline void* close_fd_ptr(void *p) { + safe_close(PTR_TO_FD(p)); + return NULL; +} + DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(FILE*, pclose, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL); diff --git a/src/network/netdev/tuntap.c b/src/network/netdev/tuntap.c index 9e909d1abce..97b4b928e76 100644 --- a/src/network/netdev/tuntap.c +++ b/src/network/netdev/tuntap.c @@ -33,11 +33,6 @@ static TunTap* TUNTAP(NetDev *netdev) { } } -static void *close_fd_ptr(void *p) { - safe_close(PTR_TO_FD(p)); - return NULL; -} - DEFINE_PRIVATE_HASH_OPS_FULL(named_fd_hash_ops, char, string_hash_func, string_compare_func, free, void, close_fd_ptr); int manager_add_tuntap_fd(Manager *m, int fd, const char *name) {