Revision: 75737
          http://sourceforge.net/p/brlcad/code/75737
Author:   starseeker
Date:     2020-05-07 19:15:16 +0000 (Thu, 07 May 2020)
Log Message:
-----------
Merge whereami.c OpenBSD libbu fallback from bioh

Modified Paths:
--------------
    brlcad/trunk/src/libbu/progname.c
    brlcad/trunk/src/libbu/tests/dylib/run.c
    brlcad/trunk/src/libbu/whereami.c

Property Changed:
----------------
    brlcad/trunk/
    brlcad/trunk/include/
    brlcad/trunk/src/libbu/
    brlcad/trunk/src/other/
    brlcad/trunk/src/other/libregex/

Index: brlcad/trunk
===================================================================
--- brlcad/trunk        2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk        2020-05-07 19:15:16 UTC (rev 75737)

Property changes on: brlcad/trunk
___________________________________________________________________
Modified: svn:mergeinfo
## -1,5 +1,5 ##
 
/brlcad/branches/RELEASE:57439,57447-57860,69901-69913,70323-70333,71915-72242,72525-72534,72826-72858,74376-74454,74964-75140,75682-75685
-/brlcad/branches/bioh:75720-75728
+/brlcad/branches/bioh:75720-75736
 
/brlcad/branches/brep-debug:61373,61375,61404,61427,61429,61470,61544,61567,61576,61999,62018,62094,62098,62107,62117,62406,62416-62519,62521-62584,62593-62614,62623,62658,62660-62674,62681-62771,62876,62901,62907,62910,62925,62928,62931-63025,63027,63051,63054-63056,63069,63071-63073,63122,63160-63161,63165,63171,63184,63187,63189-63190,63193-63196,63200,63202,63205-63210,63213,63219-63225,63232-63233,63236,63238,63338,63350-63353,63481,63618,63669,64173-64174,64176-64177,64229-64233,64242,64244,64360-64362,65165,65245,65249,65334,65833-65834,66370-66375,66931-66932,66934,67012-67015,67018-67019,67021-67022,67406,67740,67746-67748,67950,67952,68144-68145,68636,68640-68643,68820,69081,69109,69168,69206,69289,69346,69460-69461,69582-69583,69719-69721,69857-69859,69927,69995-69996,70148-70149,70347-70349,70377,70526-70527,71006-71007,71009-71022,71046-71047,71049,71096-71100
 /brlcad/branches/bullet:62518
 /brlcad/branches/cmake:43219
Index: brlcad/trunk/include
===================================================================
--- brlcad/trunk/include        2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/include        2020-05-07 19:15:16 UTC (rev 75737)

Property changes on: brlcad/trunk/include
___________________________________________________________________
Modified: svn:mergeinfo
## -1,5 +1,5 ##
 
/brlcad/branches/RELEASE/include:57439,57447-57860,69901-69913,71915-72242,72525-72534,72826-72858,74376-74454,74964-75140
-/brlcad/branches/bioh/include:75720-75728
+/brlcad/branches/bioh/include:75720-75736
 
/brlcad/branches/brep-debug/include:61373,61375,61404,61427,61429,61470,61544,61567,61576,61999,62018,62094,62098,62107,62117,62406,62416-62519,62521-62584,62593-62614,62623,62658,62660-62674,62681-62771,62876,62901,62907,62910,62925,62928,62931-63025,63027,63051,63054-63056,63069,63071-63073,63122,63160-63161,63165,63171,63184,63187,63189-63190,63193-63196,63200,63202,63205-63210,63213,63219-63225,63232-63233,63236,63238,63338,63350-63353,63481,63618,63669,64173-64174,64176-64177,64229-64233,64242,64244,64360-64362,65165,65245,65249,65334,65833-65834,66370-66375,66931-66932,66934,67012-67015,67018-67019,67021-67022,67406,67740,67746-67748,67950,67952,68144-68145,68636,68640-68643,68820,69081,69109,69206,69289,69346,69460-69461,69582-69583,69719-69721,69857-69859,69927
 /brlcad/branches/bullet/include:62518
 /brlcad/branches/cmake/include:43219
Index: brlcad/trunk/src/libbu
===================================================================
--- brlcad/trunk/src/libbu      2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/src/libbu      2020-05-07 19:15:16 UTC (rev 75737)

Property changes on: brlcad/trunk/src/libbu
___________________________________________________________________
Modified: svn:mergeinfo
## -1,4 +1,4 ##
 
/brlcad/branches/RELEASE/src/libbu:70323-70333,71915-71935,72826-72858,74376-74454
-/brlcad/branches/bioh/src/libbu:75720-75728
+/brlcad/branches/bioh/src/libbu:75720-75736
 
/brlcad/branches/brep-debug/src/libbu:69168,69927,69995-69996,70148-70149,70347-70349,70377,70526-70527,71006-71007,71009-71022,71046-71047,71049,71096-71100
 /brlcad/branches/tcltk86/src/libbu:68300-75257
\ No newline at end of property
Modified: brlcad/trunk/src/libbu/progname.c
===================================================================
--- brlcad/trunk/src/libbu/progname.c   2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/src/libbu/progname.c   2020-05-07 19:15:16 UTC (rev 75737)
@@ -65,6 +65,11 @@
 static char bu_progname[MAXPATHLEN] = {0};
 const char *DEFAULT_PROGNAME = "(" PACKAGE_NAME ")";
 
+const char *
+_bu_progname_raw()
+{
+    return (const char *)bu_progname;
+}
 
 const char *
 bu_argv0_full_path(void)

Modified: brlcad/trunk/src/libbu/tests/dylib/run.c
===================================================================
--- brlcad/trunk/src/libbu/tests/dylib/run.c    2020-05-07 19:02:00 UTC (rev 
75736)
+++ brlcad/trunk/src/libbu/tests/dylib/run.c    2020-05-07 19:15:16 UTC (rev 
75737)
@@ -16,10 +16,13 @@
 #include "bu.h"
 #include "dylib.h"
 
-int main() {
+int main(int UNUSED(ac), const char *av[]) {
     int expected_plugins = 2;
     struct bu_ptbl plugins = BU_PTBL_INIT_ZERO;
     struct bu_ptbl handles = BU_PTBL_INIT_ZERO;
+
+    bu_setprogname(av[0]);
+
     int pcnt = dylib_load_plugins(&plugins, &handles);
     if (pcnt != expected_plugins) {
        bu_log("Expected %d plugins, found %d.\n", expected_plugins, pcnt);

Modified: brlcad/trunk/src/libbu/whereami.c
===================================================================
--- brlcad/trunk/src/libbu/whereami.c   2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/src/libbu/whereami.c   2020-05-07 19:15:16 UTC (rev 75737)
@@ -21,9 +21,17 @@
 
 #include "common.h"
 
+#include <string.h>
+
+#include "bu/app.h"
+#include "bu/file.h"
 #include "bu/log.h"
+#include "bu/str.h"
+#include "bu/vls.h"
 #include "bu/malloc.h"
 
+extern const char *_bu_progname_raw(void);
+
 #define WAI_MALLOC(size) bu_malloc(size, "WAI_MALLOC")
 #define WAI_FREE(p) bu_free(p, "WAI_FREE")
 #define WAI_REALLOC(p, size) bu_realloc(p, size, "WAI_REALLOC")
@@ -707,12 +715,51 @@
 
 #else
 
-/* On OpenBSD, it apparently isn't possible to get this at all?  
https://stackoverflow.com/a/38255753 */
-
+/* LIBBU fallback implementation */
 WAI_FUNCSPEC
-int WAI_PREFIX(getExecutablePath)(char* UNUSED(out), int UNUSED(capacity), 
int* UNUSED(dirname_length))
+int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
 {
-    return -1;
+    const char *pname = _bu_progname_raw();
+    struct bu_vls epath = BU_VLS_INIT_ZERO;
+
+    if (pname[0] == '.') {
+        char iwd[MAXPATHLEN];
+        char fullpath[MAXPATHLEN];
+        bu_getiwd(iwd, MAXPATHLEN);
+       // Use a VLS for this, since in principle there's nothing stopping the
+       // iwd and the bu_progname each individually from running right up to
+       // MAXPATHLEN, and if they do a MAXPATHLEN buffer won't hold both of
+       // them for realpath to try and digest down into something sane.
+        bu_vls_sprintf(&epath, "%s%c%s", iwd, BU_DIR_SEPARATOR, pname);
+        if (!bu_file_realpath(bu_vls_cstr(&epath), fullpath)) {
+            /* Unable to resolve initial path concatentation */
+           bu_vls_free(&epath);
+           return -1;
+        }
+       bu_vls_sprintf(&epath, "%s", fullpath);
+    } else {
+       bu_vls_sprintf(&epath, "%s", pname);
+    }
+
+    int length = bu_vls_strlen(&epath);
+    if (length <= capacity) {
+
+       memcpy(out, bu_vls_cstr(&epath), length);
+
+       if (dirname_length) {
+           int i;
+           for (i = length - 1; i >= 0; --i) {
+               if (out[i] == '/') {
+                   *dirname_length = i;
+                   break;
+               }
+           }
+       }
+    }
+
+    bu_vls_free(&epath);
+
+    return length;
 }
 
 WAI_NOINLINE WAI_FUNCSPEC
@@ -726,3 +773,13 @@
 #ifdef __cplusplus
 }
 #endif
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */

Index: brlcad/trunk/src/other
===================================================================
--- brlcad/trunk/src/other      2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/src/other      2020-05-07 19:15:16 UTC (rev 75737)

Property changes on: brlcad/trunk/src/other
___________________________________________________________________
Modified: svn:mergeinfo
## -1,5 +1,5 ##
 
/brlcad/branches/RELEASE/src/other:57439,57447-57860,69901-69913,71917-72242,72525-72534,72826-72858,74376-74454,75682-75685
-/brlcad/branches/bioh/src/other:75720-75728
+/brlcad/branches/bioh/src/other:75720-75736
 
/brlcad/branches/brep-debug/src/other:61373,61375,61404,61427,61429,61470,61544,61567,61576,61999,62018,62094,62098,62107,62117,62406,62416-62519,62521-62584,62593-62614,62623,62658,62660-62674,62681-62771,62876,62901,62907,62910,62925,62928,62931-63025,63027,63051,63054-63056,63069,63071-63073,63122,63160-63161,63165,63171,63184,63187,63189-63190,63193-63196,63200,63202,63205-63210,63213,63219-63225,63232-63233,63236,63238,63338,63350-63353,63481,63618,63669,64173-64174,64176-64177,64229-64233,64242,64244,64360-64362,65165,65245,65249,65334,65833-65834,66370-66375,66931-66932,66934,67012-67015,67018-67019,67021-67022,67406,67740,67746-67748,67950,67952,68144-68145,68636,68640-68643,68820,69081,69109,69206,69289,69346,69460-69461,69582-69583,69719-69721,69857-69859,69927
 /brlcad/branches/bullet/src/other:62518
 /brlcad/branches/cmake/src/other:43219
Index: brlcad/trunk/src/other/libregex
===================================================================
--- brlcad/trunk/src/other/libregex     2020-05-07 19:02:00 UTC (rev 75736)
+++ brlcad/trunk/src/other/libregex     2020-05-07 19:15:16 UTC (rev 75737)

Property changes on: brlcad/trunk/src/other/libregex
___________________________________________________________________
Modified: svn:mergeinfo
## -1,5 +1,5 ##
 
/brlcad/branches/RELEASE/src/other/libregex:57439,57447-57860,69901-69913,71917-72242,72525-72534,72826-72858,74376-74454
-/brlcad/branches/bioh/src/other/libregex:75720-75728
+/brlcad/branches/bioh/src/other/libregex:75720-75736
 
/brlcad/branches/brep-debug/src/other/libregex:61373,61375,61404,61427,61429,61470,61544,61567,61576,61999,62018,62094,62098,62107,62117,62406,62416-62519,62521-62584,62593-62614,62623,62658,62660-62674,62681-62771,62876,62901,62907,62910,62925,62928,62931-63025,63027,63051,63054-63056,63069,63071-63073,63122,63160-63161,63165,63171,63184,63187,63189-63190,63193-63196,63200,63202,63205-63210,63213,63219-63225,63232-63233,63236,63238,63338,63350-63353,63481,63618,63669,64173-64174,64176-64177,64229-64233,64242,64244,64360-64362,65165,65245,65249,65334,65833-65834,66370-66375,66931-66932,66934,67012-67015,67018-67019,67021-67022,67406,67740,67746-67748,67950,67952,68144-68145,68636,68640-68643,68820,69081,69109,69206,69289,69346,69460-69461,69582-69583,69719-69721,69857-69859,69927
 /brlcad/branches/bullet/src/other/libregex:62518
 /brlcad/branches/cmake/src/other/libregex:43219
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to