summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/fix-argv0.cpp22
-rw-r--r--compat/fix-argv0.hpp3
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; }