From 9f81a8dd0ee585a360ae0ae7786959630a8d0be0 Mon Sep 17 00:00:00 2001 From: наб Date: Mon, 11 Nov 2024 16:17:35 +0100 Subject: dpkgpm: lift out CopyIndented() and make_unique_*() for FILEs; use getline() for reading lines instead of 1k buffer --- apt-pkg/contrib/fileutl.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'apt-pkg/contrib/fileutl.h') diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 11f4871f6..938d1d8bc 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -284,4 +285,32 @@ APT_HIDDEN bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd); APT_HIDDEN int Inhibit(const char *what, const char *who, const char *why, const char *mode); + +namespace { + struct FILEFcloseDeleter { + void operator()(FILE *p) { + fclose(p); + } + }; + struct FILEPcloseDeleter { + void operator()(FILE *p) { + pclose(p); + } + }; + + [[maybe_unused]] std::unique_ptr make_unique_FILE(const char *const filename, char const *const mode) + { + return {fopen(filename, mode), {}}; + } + [[maybe_unused]] std::unique_ptr make_unique_FILE(std::string const &filename, char const *const mode) + { + return make_unique_FILE(filename.c_str(), mode); + } + + [[maybe_unused]] std::unique_ptr make_unique_popen(const char *program, char const *const mode) + { + return {popen(program, mode), {}}; + } +} + #endif -- cgit v1.2.3-70-g09d2