Add a unique_ptr type to manage the lifetime of a `FILE *`, with a
custom deleter that calls fclose.
Change-Id: Idded4546d2a709cd0652975ef83c3ad6a0f511bc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8172
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10843
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
vector.hpp \
std-int.hpp \
read-fixed-len-int.hpp \
vector.hpp \
std-int.hpp \
read-fixed-len-int.hpp \
+ glib-up.hpp \
+ libc-up.hpp
--- /dev/null
+/*
+ * Copyright (c) 2022 EfficiOS, inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_LIBC_UP_HPP
+#define BABELTRACE_CPP_COMMON_LIBC_UP_HPP
+
+#include <cstdio>
+#include <memory>
+
+namespace bt2_common {
+namespace internal {
+
+struct FileCloserDeleter
+{
+ void operator()(std::FILE * const f) noexcept
+ {
+ std::fclose(f);
+ }
+};
+
+} /* namespace internal */
+
+using FileUP = std::unique_ptr<std::FILE, internal::FileCloserDeleter>;
+
+} /* namespace bt2_common */
+
+#endif /* BABELTRACE_CPP_COMMON_LIBC_UP_HPP */