8 #define SCARAB_API_EXPORTS 20 #include <mach-o/dyld.h> 32 LOGGER( slog,
"scarab_version" );
78 combine( a_maj_ver, a_min_ver, a_patch_ver );
148 if( a_ver ==
"unknown" )
157 size_t t_delim_pos_1 = a_ver.find(
s_delimeter, 0 );
158 if( t_delim_pos_1 == std::string::npos )
160 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find first delimeter)" );
163 std::stringstream t_maj_ver_str;
164 t_maj_ver_str << a_ver.substr( 0, t_delim_pos_1 );
166 size_t t_delim_pos_2 = a_ver.find(
s_delimeter, t_delim_pos_1 + 1 );
167 if( t_delim_pos_2 == std::string::npos )
169 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find second delimeter)" );
172 std::stringstream t_min_ver_str;
173 t_min_ver_str << a_ver.substr(t_delim_pos_1 + 1, t_delim_pos_2 );
175 std::stringstream t_patch_ver;
176 t_patch_ver << a_ver.substr( t_delim_pos_2 + 1 );
188 std::stringstream t_ver_str;
196 const size_t t_bufsize = 1024;
200 char t_username_buf[ t_bufsize ];
201 DWORD t_bufsize_win = t_bufsize;
202 if( GetUserName( t_username_buf, &t_bufsize_win ) )
210 passwd* t_passwd = getpwuid( getuid() );
211 if( t_passwd !=
nullptr )
217 LWARN( slog,
"Error reported while getting passwd info: " << strerror( errno ) );
219 LWARN( slog,
"Unable to get the username" );
223 char t_hostname_buf[ t_bufsize ];
226 WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
229 if( gethostname( t_hostname_buf, t_bufsize ) == 0 )
235 LWARN( slog,
"Unable to get the hostname" );
244 TCHAR t_exe_buf[ MAX_PATH ];
245 if( ! GetModuleFileName( NULL, t_exe_buf, MAX_PATH ) )
247 char t_exe_buf[ 2048 ];
248 uint32_t t_exe_bufsize =
sizeof( t_exe_buf );
249 if( _NSGetExecutablePath( t_exe_buf, &t_exe_bufsize ) != 0 )
251 const size_t t_exe_bufsize = 2048;
252 char t_exe_buf[ t_exe_bufsize ];
253 ssize_t t_exe_name_len = readlink(
"/proc/self/exe", t_exe_buf, t_exe_bufsize );
254 if( t_exe_name_len >= 0 )
256 t_exe_buf[t_exe_name_len] =
'\0';
262 LWARN( slog,
"Could not retrieve executable file name" );
264 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
274 std::stringstream t_info_stream;
276 t_info_stream <<
"Executable: " << t_exe_path.filename() <<
'\n';
277 t_info_stream <<
"Location: " << t_exe_path.parent_path() <<
'\n';
279 t_info_stream <<
"Git commit: " <<
f_commit;
280 std::string t_version_info( t_info_stream.str() );
281 return t_version_info;
version_ifc & operator=(const version_ifc &)
bool update_exe_host_user()
bool combine(unsigned a_maj_ver, unsigned a_min_ver, unsigned a_patch_ver)
LOGGER(mtlog, "authentication")
virtual std::string version_info_string() const
bool operator<(const version_semantic &a_other)
Less-than operator to compare version information only.
version_semantic & operator=(const version_semantic &a_orig)
Contains the logger class and macros, based on Kasper's KLogger class.
bool operator==(const version_semantic &a_other)
Equality operator to compare version information only.
bool parse(const std::string &a_ver)