2
3
6
7
8
9
22#if defined( __FreeBSD__ )
23 #define RESTINIO_FREEBSD_TARGET
24#elif defined(__APPLE__) && defined( __MACH__ )
25 #define RESTINIO_MACOS_TARGET
29
37
38
39
40
41
53#if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET )
54 file_descriptor_t file_descriptor = ::open( file_path, O_RDONLY );
62 RESTINIO_FMT_FORMAT_STRING(
"unable to openfile '{}': {}" ),
67 return file_descriptor;
71
72
73
74
75
76
77
78
79
80
81
82
85open_file(
const std::filesystem::path & file_path )
89 return open_file( file_path.c_str() );
93template <
typename META >
100 throw exception_t{
"invalid file descriptor" };
103#if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET )
104 struct stat file_stat;
106 const auto fstat_rc = ::fstat( fd, &file_stat );
108 struct stat64 file_stat;
110 const auto fstat_rc = fstat64( fd, &file_stat );
117 RESTINIO_FMT_FORMAT_STRING(
"unable to get file stat : {}" ),
122 const std::chrono::system_clock::time_point
124#if defined( RESTINIO_MACOS_TARGET )
125 std::chrono::seconds( file_stat.st_mtimespec.tv_sec ) +
126 std::chrono::microseconds( file_stat.st_mtimespec.tv_nsec / 1000 )
128 std::chrono::seconds( file_stat.st_mtim.tv_sec ) +
129 std::chrono::microseconds( file_stat.st_mtim.tv_nsec / 1000 )
133 return META{
static_cast< file_size_t >( file_stat.st_size ), last_modified };
constexpr file_descriptor_t null_file_descriptor()
Get file descriptor which stands for null.
file_descriptor_t open_file(const char *file_path)
Open file.
std::FILE * file_descriptor_t
file_descriptor_t open_file(const std::filesystem::path &file_path)
Helper function that accepts std::filesystem::path.