Revision: 45068
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45068&view=rev
Author:   brlcad
Date:     2011-06-16 14:34:34 +0000 (Thu, 16 Jun 2011)

Log Message:
-----------
simplify bu_getprogname().  forget about trying to cash the progname result and 
just re-evaluate the name again.   this is necessary anyways in case the caller 
repeatedly calls bu_setprogname() with different values.  also add protection 
from bu_basename() which will return '.' or '/' for some strings and that's not 
very useful.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/progname.c

Modified: brlcad/trunk/src/libbu/progname.c
===================================================================
--- brlcad/trunk/src/libbu/progname.c   2011-06-16 14:24:21 UTC (rev 45067)
+++ brlcad/trunk/src/libbu/progname.c   2011-06-16 14:34:34 UTC (rev 45068)
@@ -175,16 +175,8 @@
 const char *
 bu_getprogname(void) {
     const char *name = NULL;
-    static char buffer[MAXPATHLEN] = {0};
-    char *tmp_basename;
+    char *tmp_basename = NULL;
 
-    if (bu_progname[0] != '\0') {
-       tmp_basename = bu_basename(bu_progname);
-       bu_strlcpy(buffer, tmp_basename, strlen(tmp_basename)+1);
-       bu_free(tmp_basename, "tmp_basename free");
-       return buffer;
-    }
-
 #ifdef HAVE_GETPROGNAME
     name = getprogname(); /* not malloc'd memory */
 #endif
@@ -193,12 +185,15 @@
        name = _bu_argv0();
     }
 
-    snprintf(bu_progname, MAXPATHLEN, "%s", name);
+    tmp_basename = bu_basename(name);
+    if (!BU_STR_EQUAL(tmp_basename, ".") && !BU_STR_EQUAL(tmp_basename, "/")) {
+       bu_strlcpy(bu_progname, tmp_basename, MAXPATHLEN);
+       bu_free(tmp_basename, "tmp_basename free");
+    } else {
+       bu_strlcpy(bu_progname, name, MAXPATHLEN);
+    }
 
-    tmp_basename = bu_basename(bu_progname);
-    bu_strlcpy(buffer, tmp_basename, strlen(tmp_basename)+1);
-    bu_free(tmp_basename, "tmp_basename free");
-    return buffer;
+    return bu_progname;
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to