Revision: 78009
http://sourceforge.net/p/brlcad/code/78009
Author: starseeker
Date: 2020-12-18 21:33:39 +0000 (Fri, 18 Dec 2020)
Log Message:
-----------
Apply DEPRECATED to bu_argv0_full_path. Update instances of its use in our
code to use other information - needs review, particularly the libbu crash and
backtrace pieces.
Modified Paths:
--------------
brlcad/trunk/include/bu/app.h
brlcad/trunk/src/libbu/backtrace.c
brlcad/trunk/src/libbu/brlcad_path.c
brlcad/trunk/src/libbu/crashreport.c
brlcad/trunk/src/libbu/dir.c
brlcad/trunk/src/libbu/tests/progname.c
brlcad/trunk/src/libbu/whereami.h
brlcad/trunk/src/mged/setup.c
Modified: brlcad/trunk/include/bu/app.h
===================================================================
--- brlcad/trunk/include/bu/app.h 2020-12-18 20:29:36 UTC (rev 78008)
+++ brlcad/trunk/include/bu/app.h 2020-12-18 21:33:39 UTC (rev 78009)
@@ -51,7 +51,7 @@
* identified but should never return NULL. this routine is not
* thread-safe.
*/
-BU_EXPORT extern const char *bu_argv0_full_path(void);
+DEPRECATED BU_EXPORT extern const char *bu_argv0_full_path(void);
/**
* Routine for obtaining the current working directory.
Modified: brlcad/trunk/src/libbu/backtrace.c
===================================================================
--- brlcad/trunk/src/libbu/backtrace.c 2020-12-18 20:29:36 UTC (rev 78008)
+++ brlcad/trunk/src/libbu/backtrace.c 2020-12-18 21:33:39 UTC (rev 78009)
@@ -444,7 +444,7 @@
/* MUST give gdb path to binary, otherwise attach bug causes
* process kill on some platforms (e.g., FreeBSD9+AMD64)
*/
- bu_strlcpy(debugger_args[1], bu_argv0_full_path(), MAXPATHLEN);
+ bu_strlcpy(debugger_args[1], bu_dir(NULL, 0, BU_DIR_BIN,
bu_getprogname(), BU_DIR_EXT, NULL), MAXPATHLEN);
} else if (have_lldb) {
bu_strlcpy(debugger_args[0], path_lldb, MAXPATHLEN);
}
Modified: brlcad/trunk/src/libbu/brlcad_path.c
===================================================================
--- brlcad/trunk/src/libbu/brlcad_path.c 2020-12-18 20:29:36 UTC (rev
78008)
+++ brlcad/trunk/src/libbu/brlcad_path.c 2020-12-18 21:33:39 UTC (rev
78009)
@@ -28,6 +28,8 @@
#include <string.h>
#include "bio.h"
+#include "whereami.h"
+
#include "bu/app.h"
#include "bu/debug.h"
#include "bu/file.h"
@@ -200,11 +202,14 @@
return NULL;
}
+extern int _bu_dir_join_path(char result[MAXPATHLEN], const char *lhs, const
char *rhs, struct bu_vls *searched, const char *where);
+
const char *
bu_brlcad_root(const char *rhs, int fail_quietly)
{
static char result[MAXPATHLEN] = {0};
const char *lhs;
+ int length, dirname_length;
struct bu_vls searched = BU_VLS_INIT_ZERO;
char where[MAX_WHERE_SIZE] = {0};
@@ -229,28 +234,35 @@
}
/* run-time path identification */
- lhs = bu_argv0_full_path();
- snprintf(where, MAX_WHERE_SIZE, "\trun-time path identification
[UNKNOWN]\n");
- if (lhs) {
- char *dirpath;
- char *real_path = bu_file_realpath(lhs, NULL);
- dirpath = bu_path_dirname(real_path);
- snprintf(real_path, MAXPATHLEN, "%s", dirpath);
- bu_free(dirpath, "free bu_path_dirname");
- dirpath = bu_path_dirname(real_path);
- snprintf(real_path, MAXPATHLEN, "%s", dirpath);
- bu_free(dirpath, "free bu_path_dirname");
- if (join_path(result, real_path, rhs, &searched, where)) {
- if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
- bu_log("Found: Run-time path identification [%s]\n", result);
+ length = wai_getExecutablePath(NULL, 0, &dirname_length);
+ if (length > 0) {
+ char *plhs = (char *)bu_calloc(length+1, sizeof(char), "program path");
+ wai_getExecutablePath(plhs, length, &dirname_length);
+ plhs[length] = '\0';
+ snprintf(where, MAX_WHERE_SIZE, "\trun-time path identification
[UNKNOWN]\n");
+ if (strlen(plhs)) {
+ char *dirpath;
+ char *real_path = bu_file_realpath(plhs, NULL);
+ dirpath = bu_path_dirname(real_path);
+ snprintf(real_path, MAXPATHLEN, "%s", dirpath);
+ bu_free(dirpath, "free bu_path_dirname");
+ dirpath = bu_path_dirname(real_path);
+ snprintf(real_path, MAXPATHLEN, "%s", dirpath);
+ bu_free(dirpath, "free bu_path_dirname");
+ if (_bu_dir_join_path(result, real_path, rhs, &searched, where)) {
+ if (UNLIKELY(bu_debug & BU_DEBUG_PATHS)) {
+ bu_log("Found: Run-time path identification [%s]\n",
result);
+ }
+ bu_vls_free(&searched);
+ bu_free(real_path, "free real_path");
+ bu_free(plhs, "free plhs");
+ return result;
}
- bu_vls_free(&searched);
bu_free(real_path, "free real_path");
- return result;
+ } else {
+ bu_vls_strcat(&searched, where);
}
- bu_free(real_path, "free real_path");
- } else {
- bu_vls_strcat(&searched, where);
+ bu_free(plhs, "free plhs");
}
/* BRLCAD_ROOT compile-time path */
Modified: brlcad/trunk/src/libbu/crashreport.c
===================================================================
--- brlcad/trunk/src/libbu/crashreport.c 2020-12-18 20:29:36 UTC (rev
78008)
+++ brlcad/trunk/src/libbu/crashreport.c 2020-12-18 21:33:39 UTC (rev
78009)
@@ -59,7 +59,7 @@
/* vat time ist? */
(void)time(&now);
- path = bu_argv0_full_path();
+ path = bu_dir(NULL, 0, BU_DIR_BIN, bu_getprogname(), BU_DIR_EXT, NULL);
/* do our own expansion to avoid heap allocation */
snprintf(buffer, CR_BUFSIZE,
"******************************************\n\n"
Modified: brlcad/trunk/src/libbu/dir.c
===================================================================
--- brlcad/trunk/src/libbu/dir.c 2020-12-18 20:29:36 UTC (rev 78008)
+++ brlcad/trunk/src/libbu/dir.c 2020-12-18 21:33:39 UTC (rev 78009)
@@ -303,7 +303,8 @@
*
* @return boolean on whether a match was found.
*/
-static int
+// TODO - this can be static once bu_brlcad_root is removed
+int
_bu_dir_join_path(char result[MAXPATHLEN], const char *lhs, const char *rhs,
struct bu_vls *searched, const char *where)
{
size_t llen, rlen;
Modified: brlcad/trunk/src/libbu/tests/progname.c
===================================================================
--- brlcad/trunk/src/libbu/tests/progname.c 2020-12-18 20:29:36 UTC (rev
78008)
+++ brlcad/trunk/src/libbu/tests/progname.c 2020-12-18 21:33:39 UTC (rev
78009)
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <string.h>
+#include "../whereami.h"
+
#include "bu.h"
@@ -35,6 +37,8 @@
const char *ans;
const char *res;
char *tbasename;
+ int length, dirname_length;
+ char *plhs = NULL;
bu_setprogname(av[0]);
@@ -42,6 +46,13 @@
fprintf(stderr, "Usage: %s\n", av[0]);
return 1;
}
+ length = wai_getExecutablePath(NULL, 0, &dirname_length);
+ if (length > 0) {
+ label = "CASE 4";
+ plhs = (char *)bu_calloc(length+1, sizeof(char), "program path");
+ wai_getExecutablePath(plhs, length, &dirname_length);
+ plhs[length] = '\0';
+ }
tbasename = (char *)bu_calloc(strlen(av[0]), sizeof(char), "bu_progname
basename");
@@ -103,10 +114,10 @@
/* CASE 4: set full, then get */
label = "CASE 4";
bu_setprogname(av[0]);
- bu_setprogname(bu_argv0_full_path());
+ bu_setprogname(plhs);
res = bu_getprogname();
- ans = bu_argv0_full_path();
- tbasename = (char *)bu_calloc(strlen(bu_argv0_full_path()), sizeof(char),
"bu_progname basename");
+ ans = plhs;
+ tbasename = (char *)bu_calloc(strlen(plhs), sizeof(char), "bu_progname
basename");
bu_path_basename(ans, tbasename);
if (BU_STR_EQUAL(res, ans ? ans : "") || BU_STR_EQUAL(res, tbasename)) {
@@ -132,7 +143,7 @@
/* CASE 6: set 2x full path, then get */
label = "CASE 6";
- bu_setprogname(bu_argv0_full_path());
+ bu_setprogname(plhs);
bu_setprogname("/monkey/see/monkey/do");
res = bu_getprogname();
ans = "do";
@@ -147,7 +158,7 @@
/* CASE 7: get the full path */
label = "CASE 7";
bu_setprogname(av[0]);
- res = bu_argv0_full_path();
+ res = plhs;
bu_path_basename(res, tbasename);
if (res[0] == BU_DIR_SEPARATOR || (strlen(res) > 3 && res[1] == ':' &&
(res[2] == BU_DIR_SEPARATOR || res[2] == '/'))) {
@@ -157,19 +168,8 @@
fail++;
}
- /* CASE 8: make sure bu_getprogname leaves a full path */
- label = "CASE 8";
- bu_setprogname("/monkey/see/monkey/do");
- res = bu_getprogname();
- res = bu_argv0_full_path();
- if (BU_STR_EQUAL(res, "/monkey/see/monkey/do")) {
- printf("%s: %24s -> %24s [PASSED]\n", label, res, res);
- } else {
- printf("%24s -> %24s (should match %s) [FAIL]\n", label, res,
"/monkey/see/monkey/do");
- fail++;
- }
-
bu_free(tbasename, "bu_progname basename");
+ bu_free(plhs, "wai Executable Path");
return fail;
}
Modified: brlcad/trunk/src/libbu/whereami.h
===================================================================
--- brlcad/trunk/src/libbu/whereami.h 2020-12-18 20:29:36 UTC (rev 78008)
+++ brlcad/trunk/src/libbu/whereami.h 2020-12-18 21:33:39 UTC (rev 78009)
@@ -24,6 +24,10 @@
#include "common.h"
+/* NOTE - this is only included so we can BU_EXPORT getExecutablePath for
+ * libbu's testing - whereami should NOT be considered public libbu API */
+#include "bu/defines.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -54,7 +58,7 @@
* @return the length of the executable path on success (without a terminal NUL
* character), otherwise `-1`
*/
-WAI_FUNCSPEC
+BU_EXPORT WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int*
dirname_length);
/**
Modified: brlcad/trunk/src/mged/setup.c
===================================================================
--- brlcad/trunk/src/mged/setup.c 2020-12-18 20:29:36 UTC (rev 78008)
+++ brlcad/trunk/src/mged/setup.c 2020-12-18 21:33:39 UTC (rev 78009)
@@ -426,7 +426,7 @@
{
struct bu_vls str = BU_VLS_INIT_ZERO;
struct bu_vls tlog = BU_VLS_INIT_ZERO;
- const char *name = bu_argv0_full_path();
+ const char *name = bu_dir(NULL, 0, BU_DIR_BIN, bu_getprogname(),
BU_DIR_EXT, NULL);
/* locate our run-time binary (must be called before Tcl_CreateInterp()) */
if (name) {
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