FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
fifo.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <sys/stat.h>
12#include <cstring>
13#include <filesystem>
14
16#include "../../macro.hpp"
17
18namespace ns_linux::ns_fifo
19{
20
21namespace
22{
23
24namespace fs = std::filesystem;
25
26}
27
34[[nodiscard]] inline Value<fs::path> create(fs::path const& path_file_fifo)
35{
36 fs::path path_dir_parent = path_file_fifo.parent_path();
37 // Create parent directory(ies)
38 return_if(not Try(fs::exists(path_dir_parent)) and not Try(fs::create_directories(path_dir_parent))
39 , Error("E::Failed to create upper directories '{}' for fifo '{}'", path_dir_parent, path_file_fifo)
40 );
41 // Replace old fifo if exists
42 if (Try(fs::exists(path_file_fifo)))
43 {
44 Try(fs::remove(path_file_fifo));
45 }
46 // Create fifo
47 return_if(::mkfifo(path_file_fifo.c_str(), 0666) < 0
48 , Error("E::Failed to create fifo '{}' with error '{}'", path_file_fifo, strerror(errno))
49 );
50 return path_file_fifo;
51}
52
53
54} // namespace ns_linux::ns_fifo
Enhanced error handling framework built on std::expected.
Value< fs::path > create(fs::path const &path_file_fifo)
Create a fifo object.
Definition fifo.hpp:34
Simplified macros for common control flow patterns with optional logging.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44