19 #ifndef PSTORE_OS_PROCESS_FILE_NAME_HPP 20 #define PSTORE_OS_PROCESS_FILE_NAME_HPP 46 template <
typename ProcessPathFunction,
typename BufferType>
48 static_assert (std::is_same<typename BufferType::value_type, char>::value,
49 "BufferType::value_type must be char");
50 constexpr
auto const max_reasonable_size = std::size_t{16 * 1024 * 1024};
51 auto size = std::size_t{0};
52 auto next_size = std::max (buffer.capacity (), std::size_t{2});
54 buffer.resize (next_size);
55 size = get_process_path (::pstore::gsl::make_span (buffer));
56 next_size = std::max (size, next_size + next_size / 2U);
57 }
while ((size == 0 || size >= buffer.size ()) && next_size < max_reasonable_size);
58 if (next_size >= max_reasonable_size) {
59 raise (error_code::unknown_process_path);
83 template <
typename SpanType,
typename SysCtlFunction,
typename BufferType>
85 static_assert (std::is_same<typename SpanType::element_type, int>::value,
86 "mib must be a span of integers");
89 PSTORE_ASSERT (b.size () >= 0);
90 auto const buffer_size =
static_cast<std::size_t
> (b.size ());
91 auto length = buffer_size;
93 if (ctl (mib.data (),
static_cast<unsigned int> (mib.size ()), b.data (), &length,
95 if (errno == ENOMEM) {
98 raise (
errno_erc{errno},
"sysctl(CTL_KERN/KERN_PROC/KERN_PROC_PATHNAME)");
101 return std::max (std::size_t{1}, length) - std::size_t{1};
107 #endif // PSTORE_OS_PROCESS_FILE_NAME_HPP
This class is a tiny wrapper that allows an errno value to be passed to std::make_error_code().
Definition: error.hpp:99
Definition: nonpod2.cpp:40
Provides an pstore-specific error codes and a suitable error category for them.
std::string process_file_name()
Returns the path of the current process image.
std::size_t process_file_name(ProcessPathFunction get_process_path, BufferType &buffer)
Definition: process_file_name.hpp:47