aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-12-22 22:37:45 -0800
committerGerald Combs <gerald@wireshark.org>2022-12-23 23:20:22 +0000
commit13f3ebc4e5c5aa35e8c6e63b442534050943865c (patch)
tree4bb03604e02b62de4d29ae7ebcc9c2b9b2f7d28e /wsutil
parent44511c318d3105c96aa644e141822ed23614f8b9 (diff)
Add a routine to get the path of an executable given the program name.
That reduces the number of get_progfile_dir() calls, leaving only the calls that are done either to 1) get the pathname in order to display it or 2) get the pathname in order to reset the library path. That makes it easier to figure out which get_progfile_dir() calls are made to find the directory in which (non-extcap) binaries from Wireshark are installed and which - if any - are made to figure out the directory in which *the currently-running executable* are stored. (Currently, get_progfile_dir() attemps to get the former, not the latter, so extcaps in an extcap subdirectory, for example, will get the parent directory of that subdirectory, *not* the directory in which they weere installed.)
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/filesystem.c30
-rw-r--r--wsutil/filesystem.h12
2 files changed, 40 insertions, 2 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index 1eca4cedd1..27813ffdc3 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -371,7 +371,7 @@ bool is_packet_configuration_namespace(void)
*/
#define xx_free free /* hack so checkAPIs doesn't complain */
static const char *
-get_executable_path(void)
+get_current_executable_path(void)
{
#if defined(__APPLE__)
static char *executable_path;
@@ -532,6 +532,32 @@ static void trim_progfile_dir(void)
}
/*
+ * Construct the path name of a non-extcap Wireshark executable file,
+ * given the program name. The executable name doesn't include ".exe";
+ * append it on Windows, so that callers don't have to worry about that.
+ *
+ * This presumes that all non-extcap executables are in the same directory.
+ *
+ * The returned file name was g_malloc()'d so it must be g_free()d when the
+ * caller is done with it.
+ */
+char *
+get_executable_path(const char *program_name)
+{
+ /*
+ * Fail if we don't know what directory contains the executables.
+ */
+ if (progfile_dir == NULL)
+ return NULL;
+
+#ifdef _WIN32
+ return ws_strdup_printf("%s\\%s.exe", progfile_dir, program_name);
+#else
+ return ws_strdup_printf("%s/%s", progfile_dir, program_name);
+#endif
+}
+
+/*
* Get the pathname of the directory from which the executable came,
* and save it for future use. Returns NULL on success, and a
* g_mallocated string containing an error on failure.
@@ -635,7 +661,7 @@ configuration_init(
running_in_build_directory_flag = TRUE;
}
- execname = get_executable_path();
+ execname = get_current_executable_path();
if (execname == NULL) {
/*
* OK, guess based on argv[0].
diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h
index 90dd49140f..ee84b0f657 100644
--- a/wsutil/filesystem.h
+++ b/wsutil/filesystem.h
@@ -62,6 +62,18 @@ WS_DLL_PUBLIC bool is_packet_configuration_namespace(void);
WS_DLL_PUBLIC const char *get_progfile_dir(void);
/*
+ * Construct the path name of a non-extcap Wireshark executable file,
+ * given the program name. The executable name doesn't include ".exe";
+ * append it on Windows, so that callers don't have to worry about that.
+ *
+ * This presumes that all non-extcap executables are in the same directory.
+ *
+ * The returned file name was g_malloc()'d so it must be g_free()d when the
+ * caller is done with it.
+ */
+WS_DLL_PUBLIC char *get_executable_path(const char *filename);
+
+/*
* Get the directory in which plugins are stored; this must not be called
* before configuration_init() is called, as they might be stored in a
* subdirectory of the program file directory.