File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1515#pragma once
1616
1717#include < string>
18+ #include < filesystem>
1819
1920#if defined(_WIN32) || defined(_WIN64)
2021#include < windows.h>
@@ -673,4 +674,27 @@ inline std::string getVersion() {
673674 (torch::xpu::is_available () ? " , XPU" : " " ) + " )\n " ;
674675}
675676
677+ // / @brief Returns the path of the executable
678+ std::filesystem::path getExecutablePath ()
679+ {
680+ #if defined(_WIN32)
681+ char buffer[MAX_PATH];
682+ DWORD len = GetModuleFileNameA (NULL , buffer, MAX_PATH);
683+ if (len == 0 || len == MAX_PATH)
684+ throw std::runtime_error (" Failed to get executable path" );
685+ return std::filesystem::path (buffer).parent_path ();
686+
687+ #elif defined(__APPLE__)
688+ char buffer[1024 ];
689+ uint32_t size = sizeof (buffer);
690+ if (_NSGetExecutablePath (buffer, &size) != 0 )
691+ throw std::runtime_error (" Buffer too small for executable path" );
692+ return std::filesystem::canonical (buffer).parent_path ();
693+
694+ #else // Linux / Unix
695+ std::filesystem::path exe = std::filesystem::canonical (" /proc/self/exe" );
696+ return exe.parent_path ();
697+ #endif
698+ }
699+
676700} // namespace iganet
You can’t perform that action at this time.
0 commit comments