2929
3030#include < filesystem>
3131#include < fstream>
32+ #include < optional>
33+ #include < string>
3234#include < utility>
3335
3436#include " fs_util.hh"
@@ -84,7 +86,8 @@ self_path()
8486
8587 auto rc = proc_pidpath (pid, pathbuf, sizeof (pathbuf));
8688 if (rc <= 0 ) {
87- log_error (" unable to determine self path: %s" , strerror (errno));
89+ log_error (" unable to determine self path: %s" ,
90+ lnav::from_errno ().message ().c_str ());
8891 } else {
8992 log_info (" self path: %s" , pathbuf);
9093 return std::filesystem::path (pathbuf);
@@ -351,7 +354,7 @@ realpath(const std::filesystem::path& path)
351354 auto rc = ::realpath (path.c_str (), resolved);
352355
353356 if (rc == nullptr ) {
354- return Err (std::string ( strerror (errno) ));
357+ return Err (lnav::from_errno (). message ( ));
355358 }
356359
357360 return Ok (std::filesystem::path (resolved));
@@ -365,7 +368,7 @@ create_file(const std::filesystem::path& path, int flags, mode_t mode)
365368 if (fd == -1 ) {
366369 return Err (fmt::format (FMT_STRING (" Failed to open: {} -- {}" ),
367370 path.string (),
368- strerror (errno )));
371+ lnav::from_errno ( )));
369372 }
370373
371374 return Ok (auto_fd (fd));
@@ -379,7 +382,7 @@ open_file(const std::filesystem::path& path, int flags)
379382 if (fd == -1 ) {
380383 return Err (fmt::format (FMT_STRING (" Failed to open: {} -- {}" ),
381384 path.string (),
382- strerror (errno )));
385+ lnav::from_errno ( )));
383386 }
384387
385388 return Ok (auto_fd (fd));
@@ -406,7 +409,7 @@ open_temp_file(const std::filesystem::path& pattern)
406409 return Err (
407410 fmt::format (FMT_STRING (" unable to create temporary file: {} -- {}" ),
408411 pattern.string (),
409- strerror (errno )));
412+ lnav::from_errno ( )));
410413 }
411414
412415 return Ok (std::make_pair (std::filesystem::path (pattern_copy), auto_fd (fd)));
@@ -419,7 +422,7 @@ read_file(const std::filesystem::path& path)
419422 std::ifstream file_stream (path);
420423
421424 if (!file_stream) {
422- return Err (std::string ( strerror (errno) ));
425+ return Err (lnav::from_errno (). message ( ));
423426 }
424427
425428 std::string retval;
@@ -449,7 +452,7 @@ write_file(const std::filesystem::path& path,
449452 return Err (fmt::format (
450453 FMT_STRING (" unable to write to temporary file {}: {}" ),
451454 tmp_pair.first .string (),
452- strerror (errno )));
455+ lnav::from_errno ( )));
453456 }
454457
455458 if (bytes_written != sf.length ()) {
@@ -535,7 +538,7 @@ stat_file(const std::filesystem::path& path)
535538
536539 return Err (fmt::format (FMT_STRING (" failed to find file: {} -- {}" ),
537540 path.string (),
538- strerror (errno )));
541+ lnav::from_errno ( )));
539542}
540543
541544file_lock::file_lock (const std::filesystem::path& archive_path)
0 commit comments