forked from Alepha/Alepha
Make a portable hook for getting program name.
This commit is contained in:
46
System/programName.h
Normal file
46
System/programName.h
Normal file
@ -0,0 +1,46 @@
|
||||
static_assert( __cplusplus > 2020'99 );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#if defined( __FreeBSD__ )
|
||||
# include <sys/types.h>
|
||||
# include <sys/sysctl.h>
|
||||
#elif defined( _GNU_SOURCE )
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Alepha::Hydrogen::System ::detail:: programName_m
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
inline std::string
|
||||
programName()
|
||||
{
|
||||
#if defined( __FreeBSD__ )
|
||||
int mib[]
|
||||
{
|
||||
CTL_KERN,
|
||||
KERN_PROC,
|
||||
KERN_PROC_PATHNAME,
|
||||
-1,
|
||||
};
|
||||
char buf[ 4096 ];
|
||||
std::size_t cb = sizeof( buf );
|
||||
::sysctl( mib, 4, buf, &cb, nullptr, 0);
|
||||
return buf;
|
||||
#elif defined( _GNU_SOURCE )
|
||||
return ::program_invocation_short_name;
|
||||
#else
|
||||
#error "Not supported."
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Alepha::Hydrogen::System::inline exports::inline programName_m
|
||||
{
|
||||
using namespace detail::programName_m::exports;
|
||||
}
|
Reference in New Issue
Block a user