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 + "].");
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 + "].");
namespace tanchor {
-using FilePtr = std::unique_ptr<FILE, decltype(&::fclose)>;
+struct file_closer {
+ void operator() (FILE* f) const {
+ fclose(f);
+ }
+};
+
+using FilePtr = std::unique_ptr<FILE, file_closer>;
class File {
public:
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<FILE, decltype(&::pclose)>;
+ using FilePtr = std::unique_ptr<FILE, pipe_closer>;
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();
std::string cat(const char *path)
{
- using FilePtr = std::unique_ptr<FILE, decltype(&::pclose)>;
+ using FilePtr = std::unique_ptr<FILE, pipe_closer>;
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();