From c6ed11664ccb74ca11f6909039a8feca39513e72 Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Fri, 29 Mar 2024 16:52:32 +0300 Subject: [PATCH] Migrate to custom deleter type for unique_ptr This prevents the error In file included from /home/abuild/rpmbuild/BUILD/trust-anchor-2.1.2/src/file-system.cpp:22: /home/abuild/rpmbuild/BUILD/trust-anchor-2.1.2/src/file-system.hxx:29:58: error: ignoring attributes on template argument 'int (*)(FILE*)' [-Werror=ignored-attributes] 29 | using FilePtr = std::unique_ptr; | ^ ^ When building with new toolchain Change-Id: I4ef59f8a3c7d90e664f4fdd363cd385df980cd1d --- src/certificate.cpp | 2 +- src/file-system.cpp | 2 +- src/file-system.hxx | 8 +++++++- tests/test-util.cpp | 14 ++++++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/certificate.cpp b/src/certificate.cpp index 13a8f70..628f6ca 100644 --- a/src/certificate.cpp +++ b/src/certificate.cpp @@ -51,7 +51,7 @@ Certificate::Certificate(const std::string &path) : m_path(path) std::string Certificate::getSubjectNameHash() const { - FilePtr fp = FilePtr(::fopen(this->m_path.c_str(), "rb"), ::fclose); + FilePtr fp = FilePtr(::fopen(this->m_path.c_str(), "rb")); if (fp == nullptr) throw std::invalid_argument("Failed to open [" + this->m_path + "]."); diff --git a/src/file-system.cpp b/src/file-system.cpp index 55783e0..82456b4 100644 --- a/src/file-system.cpp +++ b/src/file-system.cpp @@ -40,7 +40,7 @@ void File::linkTo(const std::string &src, const std::string &dst) std::string File::read(const std::string &path) { - FilePtr fp = FilePtr(::fopen(path.c_str(), "rb"), ::fclose); + FilePtr fp = FilePtr(::fopen(path.c_str(), "rb")); if (fp == nullptr) throw std::invalid_argument("Failed to open [" + path + "]."); diff --git a/src/file-system.hxx b/src/file-system.hxx index ce1df38..1ca29c2 100644 --- a/src/file-system.hxx +++ b/src/file-system.hxx @@ -26,7 +26,13 @@ namespace tanchor { -using FilePtr = std::unique_ptr; +struct file_closer { + void operator() (FILE* f) const { + fclose(f); + } +}; + +using FilePtr = std::unique_ptr; class File { public: diff --git a/tests/test-util.cpp b/tests/test-util.cpp index 11ddd33..5c28742 100644 --- a/tests/test-util.cpp +++ b/tests/test-util.cpp @@ -32,13 +32,19 @@ namespace test { namespace util { +struct pipe_closer { + void operator() (FILE* f) const { + pclose(f); + } +}; + std::string ls(const char *path) { - using FilePtr = std::unique_ptr; + using FilePtr = std::unique_ptr; std::string cmd("/bin/ls "); cmd.append(path); - FilePtr ls(::popen(cmd.c_str(), "r"), ::pclose); + FilePtr ls(::popen(cmd.c_str(), "r")); if (ls == nullptr) return std::string(); @@ -52,11 +58,11 @@ std::string ls(const char *path) std::string cat(const char *path) { - using FilePtr = std::unique_ptr; + using FilePtr = std::unique_ptr; std::string cmd("/bin/cat "); cmd.append(path); - FilePtr ls(::popen(cmd.c_str(), "r"), ::pclose); + FilePtr ls(::popen(cmd.c_str(), "r")); if (ls == nullptr) return std::string(); -- 2.34.1