util: manually extract the program name from program_invocation_name
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 14 Jun 2018 01:00:21 +0000 (11:00 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 19 Jun 2018 02:09:56 +0000 (12:09 +1000)
Glibc has the same code to get program_invocation_short_name. However
for some reason the short name gets mangled for some wine apps.

For example with Google Earth VR I get:

program_invocation_name:
"/home/tarceri/.local/share/Steam/steamapps/common/EarthVR/Earth.exe"

program_invocation_short_name:
"e"

Acked-by: Eric Engestrom <eric.engestrom@intel.com>
src/util/xmlconfig.c

index 60a6331c86c1a36e35c92fb59c9ee484956276ee..ad943e2ce486eab8a63bc03235209c03cce5ed59 100644 (file)
 /* These aren't declared in any libc5 header */
 extern char *program_invocation_name, *program_invocation_short_name;
 #    endif
-#    define GET_PROGRAM_NAME() program_invocation_short_name
+static const char *
+__getProgramName()
+{
+    char * arg = strrchr(program_invocation_name, '/');
+    if (arg)
+        return arg+1;
+    else
+        return program_invocation_name;
+}
+#    define GET_PROGRAM_NAME() __getProgramName()
 #elif defined(__CYGWIN__)
 #    define GET_PROGRAM_NAME() program_invocation_short_name
 #elif defined(__FreeBSD__) && (__FreeBSD__ >= 2)