]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: Close function for FD_TO_PTR
authorAdrian Vovk <adrianvovk@gmail.com>
Thu, 11 Jan 2024 20:43:05 +0000 (15:43 -0500)
committerAdrian Vovk <adrianvovk@gmail.com>
Fri, 19 Jan 2024 17:27:05 +0000 (12:27 -0500)
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

src/basic/fd-util.h
src/network/netdev/tuntap.c

index 6a1143b4f301ee8bf0237fb99caa6f209edcb41c..183266513acbe408976b7966435f251fa8c0cf5a 100644 (file)
@@ -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);
 
index 9e909d1abce8bb39d47a3c477002eb48141bb5d3..97b4b928e768af45380a50d3f0660b73c56e40ec 100644 (file)
@@ -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) {