pstore2
Functions
process_file_name.hpp File Reference

Functions to return the path of the current process image. More...

#include <cerrno>
#include "pstore/support/error.hpp"
Include dependency graph for process_file_name.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string pstore::process_file_name ()
 Returns the path of the current process image.
 
template<typename ProcessPathFunction , typename BufferType >
std::size_t pstore::process_file_name (ProcessPathFunction get_process_path, BufferType &buffer)
 
template<typename SpanType , typename SysCtlFunction , typename BufferType >
std::size_t pstore::freebsd::process_file_name (SpanType mib, SysCtlFunction ctl, BufferType &buffer)
 Returns the path of the current process on FreeBSD. More...
 

Detailed Description

Functions to return the path of the current process image.

Function Documentation

◆ process_file_name() [1/2]

template<typename ProcessPathFunction , typename BufferType >
std::size_t pstore::process_file_name ( ProcessPathFunction  get_process_path,
BufferType &  buffer 
)
Template Parameters
ProcessPathFunctionThis should be a Callable type with a signature equivalent to std::function <std::size_t (gsl::span<char>)>.
BufferTypeShould be a vector-like type which supports size(),capacity(),and resize() and should be convertable to gsl::span<char>.
Parameters
get_process_pathA function which will be clled to retrieve the current process file name. It is passed a character span into which the result should be written. The return value is the number of characters places in that output buffer.
bufferA vector-like object which, on return, will contain the process file name.
Returns
The number of valid characters in the 'buffer' container.

◆ process_file_name() [2/2]

template<typename SpanType , typename SysCtlFunction , typename BufferType >
std::size_t pstore::freebsd::process_file_name ( SpanType  mib,
SysCtlFunction  ctl,
BufferType &  buffer 
)

Returns the path of the current process on FreeBSD.

This function is a wrapper around the FreeBSD sysctl() function which, amongst other things, can be used to discover the path of a process given its ID.

Note
The function is exposed here to enable unit testing.
Template Parameters
BufferTypeShould be a vector-like type which supports size(),capacity(),and resize() and should be convertable to gsl::span<char>.
SysCtlFunctionThe sysctl() function or a replacement intended for unit testung.
Parameters
mibA command array which tells the sysctl() function what to do.
ctlThe real sysctl() function or mock implementation thereof.
bufferA vector-like object which will hold the result of calling the 'ctl' function.
Returns
The number of valid characters in the 'buffer' container.