In modern C++ there is also filesystem library, it is available since C++17 #include <experimental/filesystem>
, in C++14 it was experimental #include <experimental/filesystem>
So you can you use is_fifo() now. filesystem::path
class is constructible from std::string
, which is construcible from const char*
, so filesystem::is_fifo("/path/to/file")
will work as expected. But this version can throw an exception, so bool is_fifo( const std::filesystem::path& p, std::error_code& ec ) noexcept;
is your choice.
#if __cplusplus >= 201703L
#include <filesystem>
namespace filesystem = std::filesystem;
#else
#include <experimental/filesystem>
namespace filesystem = std::experimental::filesystem;
#endif
bool is_fifo(const char *path)
{
std::error_code ec;
bool res = filesystem::is_fifo(path, ec);
if (ec.value() != 0)
std::cerr << ec.message() << std::endl;
return res;
}
And don't forget this notice:
GNU implementation prior to 9.1 requires linking with -lstdc++fs
and LLVM implementation prior to LLVM 9.0 requires linking with -lc++fs
.