#define ENV_CONFIG_PATH_VAR "WIRESHARK_CONFIG_DIR"
char *persconffile_dir = NULL;
+char *datafile_dir = NULL;
char *persdatafile_dir = NULL;
char *persconfprofile = NULL;
if (getcwd(curdir, path_max) == NULL) {
/*
* It failed - give up, and just stick
- * with DATAFILE_DIR.
+ * with DATA_DIR.
*/
g_free(curdir);
return g_strdup_printf("getcwd failed: %s\n",
*
* Otherwise, if the program was executed from the build directory, use the
* directory in which the executable for this process resides. In all other
- * cases, use the DATAFILE_DIR value that was set at compile time.
+ * cases, use the DATA_DIR value that was set at compile time.
*
* XXX - if we ever make libwireshark a real library, used by multiple
* applications (more than just TShark and versions of Wireshark with
const char *
get_datafile_dir(void)
{
- static const char *datafile_dir = NULL;
-
if (datafile_dir != NULL)
return datafile_dir;
/*
* Yes, we do; use that.
*/
- datafile_dir = progfile_dir;
+ datafile_dir = g_strdup(progfile_dir);
} else {
/*
* No, we don't.
* Fall back on the default installation directory.
*/
- datafile_dir = "C:\\Program Files\\Wireshark\\";
+ datafile_dir = g_strdup("C:\\Program Files\\Wireshark\\");
}
#else
* directory during the build which also contains executables. A special
* exception is macOS (when built with an app bundle).
*/
- datafile_dir = progfile_dir;
+ datafile_dir = g_strdup(progfile_dir);
} else {
- datafile_dir = DATAFILE_DIR;
+ datafile_dir = g_strdup(DATA_DIR);
}
#endif
}
}
+gboolean config_file_exists_with_entries(const char *fname, char comment_char)
+{
+ gboolean start_of_line = TRUE;
+ gboolean has_entries = FALSE;
+ FILE *file;
+ int c;
+
+ if (!fname) {
+ return FALSE;
+ }
+
+ if ((file = ws_fopen(fname, "r")) == NULL) {
+ return FALSE;
+ }
+
+ do {
+ c = ws_getc_unlocked(file);
+ if (start_of_line && c != comment_char && !g_ascii_isspace(c) && g_ascii_isprint(c)) {
+ has_entries = TRUE;
+ break;
+ }
+ if (c == '\n' || !g_ascii_isspace(c)) {
+ start_of_line = (c == '\n');
+ }
+ } while (c != EOF);
+
+ fclose(file);
+ return has_entries;
+}
+
/*
* Check that the from file is not the same as to file
* We do it here so we catch all cases ...
{
g_free(persconffile_dir);
persconffile_dir = NULL;
+ g_free(datafile_dir);
+ datafile_dir = NULL;
g_free(persdatafile_dir);
persdatafile_dir = NULL;
g_free(persconfprofile);