From 2058f4fb67a7728697db601df323b59f5da1f0b6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 9 Jun 2022 11:37:51 -0400 Subject: [PATCH] cpp-common: add GDirUp Add GDirUP, a unique_ptr type to manage the lifetime of GDir objects. Change-Id: I8814db0bec41918203af2f6d43a97a3e8d13c8c1 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8294 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/10845 Tested-by: jenkins CI-Build: Philippe Proulx --- src/cpp-common/glib-up.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cpp-common/glib-up.hpp b/src/cpp-common/glib-up.hpp index 4ff0ed85..5489ac75 100644 --- a/src/cpp-common/glib-up.hpp +++ b/src/cpp-common/glib-up.hpp @@ -39,6 +39,20 @@ struct GStringDeleter final using GStringUP = std::unique_ptr; +namespace internal { + +struct GDirDeleter final +{ + void operator()(GDir * const dir) + { + g_dir_close(dir); + } +}; + +} /* namespace internal */ + +using GDirUP = std::unique_ptr; + } /* namespace bt2_common */ #endif /* BABELTRACE_CPP_COMMON_GLIB_UP_HPP */ -- 2.34.1