Fix GET_PROGRAM_NAME() on Solaris to not try to modify a read-only string
authorAlan Coopersmith <alan.coopersmith@oracle.com>
Fri, 8 Apr 2011 20:03:16 +0000 (13:03 -0700)
committerAlan Coopersmith <alan.coopersmith@oracle.com>
Sat, 9 Apr 2011 00:36:46 +0000 (17:36 -0700)
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
src/mesa/drivers/dri/common/xmlconfig.c

index 0312c07..0226b38 100644 (file)
@@ -64,7 +64,25 @@ extern char *program_invocation_name, *program_invocation_short_name;
    the basename to match BSD getprogname() */
 #    include <stdlib.h>
 #    include <libgen.h>
-#    define GET_PROGRAM_NAME() basename(getexecname())
+
+static const char *__getProgramName () {
+    static const char *progname;
+
+    if (progname == NULL) {
+       const char *e = getexecname();
+       if (e != NULL) {
+           /* Have to make a copy since getexecname can return a readonly
+              string, but basename expects to be able to modify its arg. */
+           char *n = strdup(e);
+           if (n != NULL) {
+               progname = basename(n);
+           }
+       }
+    }
+    return progname;
+}
+
+#    define GET_PROGRAM_NAME() __getProgramName()
 #endif
 
 #if !defined(GET_PROGRAM_NAME)