-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #11536 from Eran: change dds participant name in context to the ex…
…ecutable name
- Loading branch information
Showing
5 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
|
||
namespace rsutils { | ||
namespace os { | ||
|
||
|
||
// Returns the path to the executable currently running | ||
std::string executable_path(); | ||
// Returns the filename component of the executable currently running | ||
std::string executable_name( bool with_extension = false ); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#include <rsutils/os/executable-name.h> | ||
|
||
#if defined( PLATFORM_POSIX ) || defined( __linux__ ) | ||
#include <fstream> | ||
#elif defined( _WIN32 ) | ||
#include <Windows.h> | ||
#elif defined( __APPLE__ ) | ||
#include <mach-o/dyld.h> | ||
#include <limits.h> // PATH_MAX is POSIX, rather than MAXPATHLEN | ||
#endif | ||
|
||
|
||
namespace rsutils { | ||
namespace os { | ||
|
||
|
||
std::string executable_path() | ||
{ | ||
#if defined( PLATFORM_POSIX ) || defined( __linux__ ) | ||
|
||
std::string sp; | ||
std::ifstream( "/proc/self/comm" ) >> sp; | ||
return sp; | ||
|
||
#elif defined( _WIN32 ) | ||
|
||
char buf[MAX_PATH]; | ||
GetModuleFileNameA( nullptr, buf, MAX_PATH ); | ||
return buf; | ||
|
||
#elif defined( __APPLE__ ) | ||
|
||
// "With deep directories the total bufsize needed could be more than MAXPATHLEN." | ||
uint32_t const max_size = PATH_MAX + 1; | ||
char buf[max_size]; | ||
uint32_t size = max_size; | ||
_NSGetExecutablePath( buf, &size ); | ||
return buf; | ||
|
||
#else | ||
|
||
static_assert( false, "unrecognized platform" ); | ||
|
||
#endif | ||
} | ||
|
||
|
||
std::string executable_name( bool with_extension ) | ||
{ | ||
auto path = executable_path(); | ||
auto sep = path.find_last_of( "/\\" ); | ||
if( sep != std::string::npos ) | ||
path = path.substr( sep + 1 ); | ||
if( ! with_extension ) | ||
{ | ||
auto period = path.find_last_of( '.' ); | ||
if( period != std::string::npos ) | ||
path.resize( period ); | ||
} | ||
return path; | ||
} | ||
|
||
|
||
} // namespace os | ||
} // namespace rsutils |