diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-04 16:49:22 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-04 16:59:25 +0100 |
commit | 555bd6dce82143394b93380b42212df99d201495 (patch) | |
tree | aec14dd9a32633834595d8a4ae1f3376ecd59a68 /compat | |
parent | 7984e3a949278265d7893e60521fc6a23a22aaef (diff) |
b
Diffstat (limited to 'compat')
-rw-r--r-- | compat/fix-argv0.cpp | 22 | ||||
-rw-r--r-- | compat/fix-argv0.hpp | 3 |
2 files changed, 25 insertions, 0 deletions
diff --git a/compat/fix-argv0.cpp b/compat/fix-argv0.cpp new file mode 100644 index 00000000..8248f58d --- /dev/null +++ b/compat/fix-argv0.cpp @@ -0,0 +1,22 @@ +#include "fix-argv0.hpp" +#include <cstring> + +namespace floormat { + +char* fix_argv0(char* argv0) noexcept +{ +#ifdef _WIN32 + if (auto* c = std::strrchr(argv0, '\\'); c && c[1]) + { + if (auto* s = std::strrchr(c, '.'); s && !std::strcmp(".exe", s)) + *s = '\0'; + return c+1; + } +#else + if (auto* c = std::strrchr(argv0, '/'); c && c[1]) + return c+1; +#endif + return argv0; +} + +} // namespace floormat diff --git a/compat/fix-argv0.hpp b/compat/fix-argv0.hpp new file mode 100644 index 00000000..dcd989aa --- /dev/null +++ b/compat/fix-argv0.hpp @@ -0,0 +1,3 @@ +#pragma once + +namespace floormat { char* fix_argv0(char* argv0) noexcept; } |