Mesa (master): Fix GET_PROGRAM_NAME() on Solaris to not try to modify a read-only string

Alan Coopersmith alanc at kemper.freedesktop.org
Fri Apr 8 17:37:29 PDT 2011


Module: Mesa
Branch: master
Commit: 64ce3933f59f71ac78d83b8b3db813b6d2619382
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=64ce3933f59f71ac78d83b8b3db813b6d2619382

Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Apr  8 13:03:16 2011 -0700

Fix GET_PROGRAM_NAME() on Solaris to not try to modify a read-only string

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

---

 src/mesa/drivers/dri/common/xmlconfig.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c
index 0312c07..0226b38 100644
--- a/src/mesa/drivers/dri/common/xmlconfig.c
+++ b/src/mesa/drivers/dri/common/xmlconfig.c
@@ -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)



More information about the mesa-commit mailing list