summaryrefslogtreecommitdiffhomepage
path: root/compat/fix-argv0.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/fix-argv0.cpp')
-rw-r--r--compat/fix-argv0.cpp22
1 files changed, 22 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