Revision: 72010
          http://sourceforge.net/p/brlcad/code/72010
Author:   starseeker
Date:     2018-11-14 22:22:11 +0000 (Wed, 14 Nov 2018)
Log Message:
-----------
Fix two issues with bu_dir.  1.  Make the return buffer be a pointer to a read 
only static MAXPATHLEN buffer if the user didn't supply a buffer, per the 
bu/app.h comments.  2. Make the lookup values for relative paths values from 
the configure-time variables, rather than hardcoded strings.  This means the 
bu_dir lookup logic will now reflect any overrids to bin, lib, etc. directory 
locations.

Modified Paths:
--------------
    brlcad/trunk/CMakeLists.txt
    brlcad/trunk/misc/CMake/Path_Setup.cmake
    brlcad/trunk/src/libbu/dir.c

Modified: brlcad/trunk/CMakeLists.txt
===================================================================
--- brlcad/trunk/CMakeLists.txt 2018-11-14 22:17:05 UTC (rev 72009)
+++ brlcad/trunk/CMakeLists.txt 2018-11-14 22:22:11 UTC (rev 72010)
@@ -925,6 +925,15 @@
 # Let programs know what the executable suffix is on this platform, if any
 CONFIG_H_APPEND(BRLCAD "#define EXECUTABLE_SUFFIX 
\"${CMAKE_EXECUTABLE_SUFFIX}\"\n")
 
+# Define the various relative paths for bu_dir (be sure to have included
+# Path_Setup.cmake before this point, as that file defines these variables.)
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_BIN_DIR \"${BIN_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_LIB_DIR \"${LIB_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_LIBEXEC_DIR \"${LIBEXEC_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_INCLUDE_DIR \"${INCLUDE_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_DATA_DIR \"${DATA_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_DOC_DIR \"${DOC_DIR}\"\n")
+CONFIG_H_APPEND(BRLCAD "#define BRLCAD_MAN_DIR \"${MAN_DIR}\"\n")
 
 #----------------------------------------------------------------------
 # If we're not debugging, we want HIDDEN to be defined as static.  Set

Modified: brlcad/trunk/misc/CMake/Path_Setup.cmake
===================================================================
--- brlcad/trunk/misc/CMake/Path_Setup.cmake    2018-11-14 22:17:05 UTC (rev 
72009)
+++ brlcad/trunk/misc/CMake/Path_Setup.cmake    2018-11-14 22:22:11 UTC (rev 
72010)
@@ -40,20 +40,18 @@
   set(BIN_DIR bin)
 endif(NOT BIN_DIR)
 
-# The location in which to install BRL-CAD header files.
-if(NOT INCLUDE_DIR)
-  set(INCLUDE_DIR include)
-endif(NOT INCLUDE_DIR)
-
 # The location in which to install BRL-CAD libraries.
 if(NOT LIB_DIR)
   set(LIB_DIR lib)
 endif(NOT LIB_DIR)
+if(NOT LIBEXEC_DIR)
+  set(LIBEXEC_DIR libexec)
+endif(NOT LIBEXEC_DIR)
 
-# The location in which to install BRL-CAD configuration files.
-if(NOT CONF_DIR)
-  set(CONF_DIR etc)
-endif(NOT CONF_DIR)
+# The location in which to install BRL-CAD header files.
+if(NOT INCLUDE_DIR)
+  set(INCLUDE_DIR include)
+endif(NOT INCLUDE_DIR)
 
 # The location in which to install BRL-CAD data files
 if(NOT DATA_DIR)
@@ -60,18 +58,18 @@
   set(DATA_DIR share)
 endif(NOT DATA_DIR)
 
+# The location in which to install BRL-CAD documentation files
+if(NOT DOC_DIR)
+  set(DOC_DIR ${DATA_DIR}/doc)
+endif(NOT DOC_DIR)
+
 # The location in which to install BRL-CAD Manual pages
 if(NOT MAN_DIR)
   set(MAN_DIR ${DATA_DIR}/man)
 endif(NOT MAN_DIR)
 
-# The location in which to install BRL-CAD documentation files
-if(NOT DOC_DIR)
-  set(DOC_DIR ${DATA_DIR}/doc)
-endif(NOT DOC_DIR)
-
 # Make sure no absolute paths have been supplied to these variables
-set(INSTALL_DIRS BIN INCLUDE LIB CONF DATA MAN DOC)
+set(INSTALL_DIRS BIN INCLUDE LIB LIBEXEC DATA MAN DOC)
 foreach(instdir ${INSTALL_DIRS})
   get_filename_component(instdir_full ${${instdir}_DIR} ABSOLUTE)
   if("${${instdir}_DIR}" STREQUAL "${instdir_full}")

Modified: brlcad/trunk/src/libbu/dir.c
===================================================================
--- brlcad/trunk/src/libbu/dir.c        2018-11-14 22:17:05 UTC (rev 72009)
+++ brlcad/trunk/src/libbu/dir.c        2018-11-14 22:22:11 UTC (rev 72010)
@@ -288,12 +288,14 @@
 vdir(char *result, size_t len, va_list args)
 {
     struct bu_vls vls = BU_VLS_INIT_ZERO;
-    char buf[MAXPATHLEN] = {0};
+    static char buf[MAXPATHLEN] = {0};
     const char *cpath;
     uintptr_t arg;
 
     arg = va_arg(args, uintptr_t);
 
+    memset(buf, 0, MAXPATHLEN);
+
     while (arg != (uintptr_t)NULL) {
        switch ((bu_dir_t)arg) {
            case BU_DIR_CURR:
@@ -304,31 +306,31 @@
                bu_log("UNIMPLEMENTED\n");
                break;
            case BU_DIR_BIN:
-               cpath = bu_brlcad_root("bin", 1);
+               cpath = bu_brlcad_root(BRLCAD_BIN_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_LIB:
-               cpath = bu_brlcad_root("lib", 1);
+               cpath = bu_brlcad_root(BRLCAD_LIB_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_LIBEXEC:
-               cpath = bu_brlcad_root("libexec", 1);
+               cpath = bu_brlcad_root(BRLCAD_LIBEXEC_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_INCLUDE:
-               cpath = bu_brlcad_root("include", 1);
+               cpath = bu_brlcad_root(BRLCAD_INCLUDE_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_DATA:
-               cpath = bu_brlcad_root("data", 1);
+               cpath = bu_brlcad_root(BRLCAD_DATA_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_DOC:
-               cpath = bu_brlcad_root("doc", 1);
+               cpath = bu_brlcad_root(BRLCAD_DOC_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_MAN:
-               cpath = bu_brlcad_root("man", 1);
+               cpath = bu_brlcad_root(BRLCAD_MAN_DIR, 1);
                append(&vls, cpath);
                break;
            case BU_DIR_TEMP:
@@ -364,9 +366,12 @@
        bu_strlcpy(result, bu_vls_cstr(&vls), len);
        bu_vls_free(&vls);
        return result;
+    } else {
+       memset(buf, 0, MAXPATHLEN);
+       bu_strlcpy(buf, bu_vls_cstr(&vls), MAXPATHLEN);
     }
     bu_vls_free(&vls);
-    return NULL;
+    return buf;
 }
 
 

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



_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to