Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Macros | Functions
filesystem.h File Reference
#include <wireshark.h>

Go to the source code of this file.

Macros

#define DEFAULT_PROFILE   "Default"
 

Functions

WS_DLL_PUBLIC char * configuration_init (const char *arg0, const char *app_flavor_lower)
 Initialize our configuration environment.
 
WS_DLL_PUBLIC const char * get_progfile_dir (void)
 Get the directory in which the main (Wireshark, TShark, Stratoshark, etc) program resides.
 
WS_DLL_PUBLIC char * get_executable_path (const char *filename)
 Given the program name, construct the path name of a non-extcap Wireshark executable file.
 
WS_DLL_PUBLIC const char * get_plugins_dir (const char *app_env_var_prefix)
 Get the directory in which plugins are stored.
 
WS_DLL_PUBLIC const char * get_plugins_dir_with_version (const char *app_env_var_prefix)
 Append VERSION_MAJOR.VERSION_MINOR to the plugin dir.
 
WS_DLL_PUBLIC const char * get_plugins_pers_dir (const char *app_env_var_prefix)
 Gets the personal plugin directory.
 
WS_DLL_PUBLIC const char * get_plugins_pers_dir_with_version (const char *app_env_var_prefix)
 Appends VERSION_MAJOR.VERSION_MINOR to the personal plugin directory path.
 
WS_DLL_PUBLIC const char * get_extcap_dir (const char *app_env_var_prefix, const char *dir_extcap)
 Gets the directory in which extcap hooks are stored.
 
WS_DLL_PUBLIC const char * get_extcap_pers_dir (const char *app_env_var_prefix)
 Gets the personal extcap directory.
 
WS_DLL_PUBLIC bool running_in_build_directory (void)
 Indicates whether Wireshark is running from a build directory.
 
WS_DLL_PUBLIC const char * get_datafile_dir (const char *app_env_var_prefix)
 Gets the directory in which global configuration files are stored.
 
WS_DLL_PUBLIC char * get_datafile_path (const char *filename, const char *app_env_var_prefix)
 Constructs the full path to a global configuration file.
 
WS_DLL_PUBLIC const char * get_doc_dir (const char *app_env_var_prefix)
 Gets the directory in which global documentation files are stored.
 
WS_DLL_PUBLIC char * get_docfile_path (const char *filename, const char *app_env_var_prefix)
 Constructs the full path to a global documentation file.
 
WS_DLL_PUBLIC char * doc_file_url (const char *filename, const char *app_env_var_prefix)
 Constructs the URL path to a global documentation file.
 
WS_DLL_PUBLIC const char * get_systemfile_dir (const char *app_env_var_prefix)
 Gets the directory in which system files are stored.
 
WS_DLL_PUBLIC void set_profile_name (const char *profilename)
 Sets the configuration profile name for storing personal configuration files.
 
WS_DLL_PUBLIC const char * get_profile_name (void)
 Gets the current configuration profile name used for storing personal configuration files.
 
WS_DLL_PUBLIC bool is_default_profile (void)
 Checks whether the current configuration profile is the default profile.
 
WS_DLL_PUBLIC bool has_global_profiles (const char *app_env_var_prefix)
 Checks whether global configuration profiles are available.
 
WS_DLL_PUBLIC char * get_profiles_dir (const char *app_env_var_prefix)
 Gets the directory used to store configuration profile directories.
 
WS_DLL_PUBLIC char * get_profile_dir (const char *app_env_var_prefix, const char *profilename, bool is_global)
 Gets the directory used to store configuration files for a given profile.
 
WS_DLL_PUBLIC int create_profiles_dir (const char *app_env_var_prefix, char **pf_dir_path_return)
 Creates the directory used to store configuration profile directories.
 
WS_DLL_PUBLIC char * get_global_profiles_dir (const char *app_env_var_prefix)
 Gets the directory used to store global configuration profile directories.
 
WS_DLL_PUBLIC void profile_store_persconffiles (bool store)
 Enables or disables tracking of personal configuration file names for profile duplication.
 
WS_DLL_PUBLIC void profile_register_persconffile (const char *filename)
 Registers a filename to the personal configuration files storage.
 
WS_DLL_PUBLIC bool profile_exists (const char *app_env_var_prefix, const char *profilename, bool global)
 Checks whether a given configuration profile exists.
 
WS_DLL_PUBLIC int create_persconffile_profile (const char *app_env_var_prefix, const char *profilename, char **pf_dir_path_return)
 Creates a directory for the given configuration profile.
 
WS_DLL_PUBLIC const GHashTable * allowed_profile_filenames (void)
 Returns the list of known profile configuration filenames.
 
WS_DLL_PUBLIC int delete_persconffile_profile (const char *app_env_var_prefix, const char *profilename, char **pf_dir_path_return)
 Deletes the directory for the given configuration profile.
 
WS_DLL_PUBLIC int rename_persconffile_profile (const char *app_env_var_prefix, const char *fromname, const char *toname, char **pf_from_dir_path_return, char **pf_to_dir_path_return)
 Renames the directory for the given configuration profile.
 
WS_DLL_PUBLIC int copy_persconffile_profile (const char *app_env_var_prefix, const char *toname, const char *fromname, bool from_global, char **pf_filename_return, char **pf_to_dir_path_return, char **pf_from_dir_path_return)
 Copies configuration files from one profile to another.
 
WS_DLL_PUBLIC int create_persconffile_dir (const char *app_env_var_prefix, char **pf_dir_path_return)
 Creates the directory that holds personal configuration files, if necessary.
 
WS_DLL_PUBLIC char * get_persconffile_path (const char *filename, bool from_profile, const char *app_env_var_prefix)
 Constructs the full path name of a personal configuration file.
 
WS_DLL_PUBLIC void set_persconffile_dir (const char *p)
 Sets the path of the personal configuration file directory.
 
WS_DLL_PUBLIC const char * get_persdatafile_dir (void)
 Gets the default directory in which personal data is stored.
 
WS_DLL_PUBLIC void set_persdatafile_dir (const char *p)
 Sets the path of the directory in which personal data is stored.
 
WS_DLL_PUBLIC WS_RETNONNULL const char * get_current_working_dir (void)
 Gets the current working directory.
 
WS_DLL_PUBLIC const char * file_open_error_message (int err, bool for_writing)
 Returns a human-readable error message for file open or create failures.
 
WS_DLL_PUBLIC const char * file_write_error_message (int err)
 Returns a human-readable error message for write operation failures.
 
WS_DLL_PUBLIC const char * get_basename (const char *path)
 Returns the last component of a pathname.
 
WS_DLL_PUBLIC char * find_last_pathname_separator (const char *path)
 Returns a pointer to the last pathname separator in a given path.
 
WS_DLL_PUBLIC char * get_dirname (char *path)
 Returns the directory portion of a pathname.
 
WS_DLL_PUBLIC int test_for_directory (const char *path)
 Tests whether a given pathname refers to a directory.
 
WS_DLL_PUBLIC int test_for_fifo (const char *path)
 Tests whether a given pathname refers to a FIFO (named pipe).
 
WS_DLL_PUBLIC bool test_for_regular_file (const char *path)
 Tests whether a given pathname refers to a regular file.
 
WS_DLL_PUBLIC bool file_exists (const char *fname)
 Checks whether a file exists.
 
WS_DLL_PUBLIC bool config_file_exists_with_entries (const char *fname, char comment_char)
 Checks if a configuration file exists and contains non-comment entries.
 
WS_DLL_PUBLIC bool files_identical (const char *fname1, const char *fname2)
 Checks whether two filenames refer to the same file.
 
WS_DLL_PUBLIC bool file_needs_reopen (int fd, const char *filename)
 Checks whether a file has been recreated since it was opened.
 
WS_DLL_PUBLIC bool write_file_binary_mode (const char *filename, const void *content, size_t content_len)
 Writes raw content to a file in binary mode.
 
WS_DLL_PUBLIC bool copy_file_binary_mode (const char *from_filename, const char *to_filename)
 Copies a file using binary mode.
 
WS_DLL_PUBLIC char * data_file_url (const char *filename, const char *app_env_var_prefix)
 Constructs a filesystem URL from a given filename.
 
WS_DLL_PUBLIC void free_progdirs (void)
 Frees internal program directory structures.
 

Detailed Description

Filesystem utility definitions

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Function Documentation

◆ allowed_profile_filenames()

WS_DLL_PUBLIC const GHashTable * allowed_profile_filenames ( void  )

Returns the list of known profile configuration filenames.

Provides access to a hash table containing the set of recognized configuration file names that are associated with user or global profiles. These filenames are used to determine which files should be included when copying or managing configuration profiles.

Returns
A pointer to a constant GHashTable containing the allowed profile configuration filenames.

◆ config_file_exists_with_entries()

WS_DLL_PUBLIC bool config_file_exists_with_entries ( const char *  fname,
char  comment_char 
)

Checks if a configuration file exists and contains non-comment entries.

Verifies that the specified file exists and includes at least one line of text that does not begin with the given comment character. This is useful for detecting meaningful configuration content while ignoring commented-out lines.

Parameters
fnameThe pathname of the configuration file to check.
comment_charThe character used to denote comments (e.g., '#').
Returns
true if the file exists and contains at least one non-comment line, false otherwise.

◆ configuration_init()

WS_DLL_PUBLIC char * configuration_init ( const char *  arg0,
const char *  app_flavor_lower 
)

Initialize our configuration environment.

Get the pathname of the directory from which the executable came, and save it for future use. If you change the default application flavor, you should should do so before calling this.

Parameters
arg0Executable name hint. Should be argv[0].
app_flavor_lower"Main" application associated with the configuration ("wireshark" or "stratoshark")
Returns
NULL on success, and a g_mallocated string containing an error on failure.

◆ copy_file_binary_mode()

WS_DLL_PUBLIC bool copy_file_binary_mode ( const char *  from_filename,
const char *  to_filename 
)

Copies a file using binary mode.

Performs a byte-for-byte copy of the source file to the destination file using binary mode. This ensures compatibility across platforms that distinguish between text and binary file handling. The function does not interpret or modify the content—it copies the raw bytes as-is.

If the copy operation fails, the function returns false and displays a simple dialog window with the corresponding error message. On success, it returns true.

Parameters
from_filenameThe path to the source file to copy.
to_filenameThe path to the destination file.
Returns
true on success, false on failure.

◆ copy_persconffile_profile()

WS_DLL_PUBLIC int copy_persconffile_profile ( const char *  app_env_var_prefix,
const char *  toname,
const char *  fromname,
bool  from_global,
char **  pf_filename_return,
char **  pf_to_dir_path_return,
char **  pf_from_dir_path_return 
)

Copies configuration files from one profile to another.

Transfers all tracked personal configuration files from the source profile to the destination profile. If the copy operation fails, the function returns -1 and sets one or more of the output parameters to indicate the file or directory involved in the failure. These strings are allocated with g_malloc() and must be freed with g_free() by the caller. On success, the function returns 0.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
tonameThe name of the destination configuration profile.
fromnameThe name of the source configuration profile.
from_globaltrue if the source profile is global, false if it is personal.
pf_filename_returnPointer to receive the g_malloc()'d name of the file that failed to copy, if any.
pf_to_dir_path_returnPointer to receive the g_malloc()'d destination directory path, if applicable.
pf_from_dir_path_returnPointer to receive the g_malloc()'d source directory path, if applicable.
Returns
0 on success, -1 on failure.

◆ create_persconffile_dir()

WS_DLL_PUBLIC int create_persconffile_dir ( const char *  app_env_var_prefix,
char **  pf_dir_path_return 
)

Creates the directory that holds personal configuration files, if necessary.

Ensures that the directory used to store personal configuration files exists, creating it if it does not. If the creation fails, the function returns -1 and sets *pf_dir_path_return to the path of the directory that could not be created. The returned string is allocated with g_malloc() and must be freed with g_free() by the caller. On success, the function returns 0.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
pf_dir_path_returnPointer to receive the g_malloc()'d path of the failed directory, if any.
Returns
0 on success, -1 on failure.

◆ create_persconffile_profile()

WS_DLL_PUBLIC int create_persconffile_profile ( const char *  app_env_var_prefix,
const char *  profilename,
char **  pf_dir_path_return 
)

Creates a directory for the given configuration profile.

Attempts to create a directory for the specified configuration profile. If the creation fails, the function returns -1 and sets *pf_dir_path_return to the path of the directory that could not be created. The returned path is allocated with g_malloc() and must be freed with g_free() by the caller. On success, the function returns 0.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
profilenameThe name of the configuration profile.
pf_dir_path_returnPointer to receive the g_malloc()'d path of the failed directory, if any.
Returns
0 on success, -1 on failure.

◆ create_profiles_dir()

WS_DLL_PUBLIC int create_profiles_dir ( const char *  app_env_var_prefix,
char **  pf_dir_path_return 
)

Creates the directory used to store configuration profile directories.

Ensures that the base directory for storing configuration profiles exists, creating it if necessary. The full path to the created or existing directory is returned via the output parameter.

The returned string is allocated with g_malloc() and must be freed with g_free() when no longer needed.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
pf_dir_path_returnPointer to a location where the directory path string will be stored.
Returns
0 on success, or a non-zero error code on failure.

◆ data_file_url()

WS_DLL_PUBLIC char * data_file_url ( const char *  filename,
const char *  app_env_var_prefix 
)

Constructs a filesystem URL from a given filename.

Converts the specified filename into a filesystem URL. If the filename is a relative path, it is automatically prefixed with the datafile directory path to form an absolute reference. This is useful for generating standardized URLs for accessing local resources.

Parameters
filenameA file name or path. Relative paths will be prefixed with the datafile directory path.
app_env_var_prefixThe prefix for the application environment variable used to get the datafile directory.
Returns
A newly allocated string containing the filesystem URL, or NULL on failure. The returned string must be freed using g_free().

◆ delete_persconffile_profile()

WS_DLL_PUBLIC int delete_persconffile_profile ( const char *  app_env_var_prefix,
const char *  profilename,
char **  pf_dir_path_return 
)

Deletes the directory for the given configuration profile.

Attempts to remove the directory associated with the specified configuration profile. If the deletion fails, the function returns -1 and sets *pf_dir_path_return to the path of the directory that could not be deleted. The returned path is allocated with g_malloc() and must be freed with g_free() by the caller. On success, the function returns 0.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
profilenameThe name of the configuration profile to delete.
pf_dir_path_returnPointer to receive the g_malloc()'d path of the failed directory, if any.
Returns
0 on success, -1 on failure.

◆ doc_file_url()

WS_DLL_PUBLIC char * doc_file_url ( const char *  filename,
const char *  app_env_var_prefix 
)

Constructs the URL path to a global documentation file.

Given a documentation file name, this function builds the corresponding URL path pointing to the global documentation location.

The returned string is allocated with g_malloc() and must be freed with g_free() when no longer needed.

Parameters
filenameThe name of the documentation file.
app_env_var_prefixThe prefix for the application environment variable used to get the global configuration directory.
Returns
A g_malloc()'d string containing the full URL path to the file.

◆ file_exists()

WS_DLL_PUBLIC bool file_exists ( const char *  fname)

Checks whether a file exists.

Determines if the file specified by the given pathname exists and is accessible. This check typically relies on file system metadata and does not open the file.

Parameters
fnameThe pathname of the file to check.
Returns
true if the file exists, false otherwise.

◆ file_needs_reopen()

WS_DLL_PUBLIC bool file_needs_reopen ( int  fd,
const char *  filename 
)

Checks whether a file has been recreated since it was opened.

Compares the current metadata of the file at the given pathname with the metadata of the file descriptor to determine if the file has been replaced or recreated. This is useful for detecting log rotation or external file updates that may require reopening the file to access the new content.

Parameters
fdThe file descriptor of the originally opened file.
filenameThe pathname of the file to compare against.
Returns
true if the file has been recreated and needs to be reopened, false otherwise.

◆ file_open_error_message()

WS_DLL_PUBLIC const char * file_open_error_message ( int  err,
bool  for_writing 
)

Returns a human-readable error message for file open or create failures.

Converts a UNIX-style errno value into a descriptive error message suitable for reporting issues encountered during file open or create operations.

Parameters
errThe errno value indicating the specific error.
for_writingtrue if the operation was a write (create) attempt, false if it was a read (open) attempt.
Returns
A pointer to a statically allocated string describing the error.

◆ file_write_error_message()

WS_DLL_PUBLIC const char * file_write_error_message ( int  err)

Returns a human-readable error message for write operation failures.

Converts a UNIX-style errno value into a descriptive error message suitable for reporting issues encountered during file write operations.

Parameters
errThe errno value indicating the specific write error.
Returns
A pointer to a statically allocated string describing the error.

◆ files_identical()

WS_DLL_PUBLIC bool files_identical ( const char *  fname1,
const char *  fname2 
)

Checks whether two filenames refer to the same file.

Compares two file paths to determine if they resolve to the same file, accounting for both absolute and relative path representations. This typically involves resolving symbolic links and canonicalizing paths before comparison.

Parameters
fname1The first file path to compare.
fname2The second file path to compare.
Returns
true if both paths refer to the same file, false otherwise.

◆ find_last_pathname_separator()

WS_DLL_PUBLIC char * find_last_pathname_separator ( const char *  path)

Returns a pointer to the last pathname separator in a given path.

Scans the provided pathname and returns a pointer to the last pathname separator character (e.g., '/' or '\' depending on platform). If the pathname contains no separators, the function returns NULL.

Parameters
pathThe pathname to scan.
Returns
A pointer to the last pathname separator character, or NULL if none is found.

◆ free_progdirs()

WS_DLL_PUBLIC void free_progdirs ( void  )

Frees internal program directory structures.

Releases any memory or resources allocated for managing program directory paths. This function should be called during cleanup to avoid memory leaks related to internal directory tracking.

◆ get_basename()

WS_DLL_PUBLIC const char * get_basename ( const char *  path)

Returns the last component of a pathname.

Extracts the final segment of the given path, typically representing the filename or directory name at the end of the path. This does not modify the input string.

Parameters
pathThe full path from which to extract the basename.
Returns
A pointer to the last component of the pathname.

◆ get_current_working_dir()

WS_DLL_PUBLIC WS_RETNONNULL const char * get_current_working_dir ( void  )

Gets the current working directory.

Returns the absolute path of the process's current working directory. This path reflects where the application is executing and may be used for resolving relative file paths.

Returns
A pointer to a statically allocated string containing the current working directory.

◆ get_datafile_dir()

WS_DLL_PUBLIC const char * get_datafile_dir ( const char *  app_env_var_prefix)

Gets the directory in which global configuration files are stored.

Returns the path to the directory containing global configuration files, typically shared across all users and installations.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the global configuration directory.
Returns
A pointer to a statically allocated string containing the global configuration directory path.

◆ get_datafile_path()

WS_DLL_PUBLIC char * get_datafile_path ( const char *  filename,
const char *  app_env_var_prefix 
)

Constructs the full path to a global configuration file.

Given a file name, this function builds the full path to the corresponding global configuration file located in the datafile directory.

The returned string is allocated with g_malloc() and must be freed with g_free() when no longer needed.

Parameters
filenameThe name of the configuration file.
app_env_var_prefixThe prefix for the application environment variable used to get the global configuration directory.
Returns
A g_malloc()'d string containing the full path to the file.

◆ get_dirname()

WS_DLL_PUBLIC char * get_dirname ( char *  path)

Returns the directory portion of a pathname.

Extracts all components of the given pathname except the last one (typically the file or final directory name). This function modifies the input string in-place to truncate it at the last pathname separator.

Note
The input pathname is overwritten. If the original value is needed later, make a copy before calling.
Parameters
pathA modifiable string containing the full path.
Returns
A pointer to the modified input string containing the directory portion.

◆ get_doc_dir()

WS_DLL_PUBLIC const char * get_doc_dir ( const char *  app_env_var_prefix)

Gets the directory in which global documentation files are stored.

Returns the path to the directory containing global documentation files, typically shared across all users and installations.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the global configuration directory.
Returns
A pointer to a statically allocated string containing the documentation directory path.

◆ get_docfile_path()

WS_DLL_PUBLIC char * get_docfile_path ( const char *  filename,
const char *  app_env_var_prefix 
)

Constructs the full path to a global documentation file.

Given a file name, this function builds the full path to the corresponding documentation file located in the global documentation directory.

The returned string is allocated with g_malloc() and must be freed with g_free() when no longer needed.

Parameters
filenameThe name of the documentation file.
app_env_var_prefixThe prefix for the application environment variable used to get the global configuration directory.
Returns
A g_malloc()'d string containing the full path to the file.

◆ get_executable_path()

WS_DLL_PUBLIC char * get_executable_path ( const char *  filename)

Given the program name, construct the path name of a non-extcap Wireshark executable file.

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.

Parameters
filenameThe base name of the executable (without extension).
Returns
A g_malloc()'d string containing the full path. Must be g_free()'d by the caller.

◆ get_extcap_dir()

WS_DLL_PUBLIC const char * get_extcap_dir ( const char *  app_env_var_prefix,
const char *  dir_extcap 
)

Gets the directory in which extcap hooks are stored.

This function returns the path to the extcap hook directory. It must not be called before configuration_init(), as the directory may be located in a subdirectory of the program file directory.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the extcap directory.
dir_extcapString of the path to extcap directory
Returns
A pointer to a statically allocated string containing the extcap directory path.

◆ get_extcap_pers_dir()

WS_DLL_PUBLIC const char * get_extcap_pers_dir ( const char *  app_env_var_prefix)

Gets the personal extcap directory.

Returns the path to the user's personal extcap directory, typically located within their home or configuration directory.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the personal extcap directory.
Returns
A pointer to a statically allocated string containing the personal extcap directory path.

◆ get_global_profiles_dir()

WS_DLL_PUBLIC char * get_global_profiles_dir ( const char *  app_env_var_prefix)

Gets the directory used to store global configuration profile directories.

Returns the path to the base directory where global (system-wide) configuration profiles are stored. The caller is responsible for freeing the returned string using g_free().

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the global profiles directory.
Returns
A g_malloc()'d string containing the global profiles directory path.

◆ get_persconffile_path()

WS_DLL_PUBLIC char * get_persconffile_path ( const char *  filename,
bool  from_profile,
const char *  app_env_var_prefix 
)

Constructs the full path name of a personal configuration file.

Builds the absolute path to a personal configuration file based on the provided filename. If configuration profiles are enabled and from_profile is true, the path will be constructed within the active profile's directory; otherwise, it will use the standard personal configuration directory.

The returned string is allocated with g_malloc() and must be freed with g_free() by the caller.

Parameters
filenameThe name of the configuration file.
from_profiletrue to use the profile-specific directory, false to use the default personal config directory.
app_env_var_prefixThe prefix for the application environment variable used to get the personal config directory.
Returns
A g_malloc()'d string containing the full path to the configuration file.

◆ get_persdatafile_dir()

WS_DLL_PUBLIC const char * get_persdatafile_dir ( void  )

Gets the default directory in which personal data is stored.

Returns the path to the default location for storing personal data files. On Windows systems, this corresponds to the "My Documents" folder within the user's profile. On UNIX-like systems, this is typically the current working directory.

Returns
A pointer to a statically allocated string containing the personal data directory path.

◆ get_plugins_dir()

WS_DLL_PUBLIC const char * get_plugins_dir ( const char *  app_env_var_prefix)

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.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get plugin directory.
Returns
A pointer to a statically allocated string containing the plugin directory path.

◆ get_plugins_dir_with_version()

WS_DLL_PUBLIC const char * get_plugins_dir_with_version ( const char *  app_env_var_prefix)

Append VERSION_MAJOR.VERSION_MINOR to the plugin dir.

Constructs the full plugin directory path by appending the current major and minor version numbers to the base plugin directory.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get plugin directory.
Returns
A pointer to a statically allocated string containing the versioned plugin directory path.

◆ get_plugins_pers_dir()

WS_DLL_PUBLIC const char * get_plugins_pers_dir ( const char *  app_env_var_prefix)

Gets the personal plugin directory.

Returns the path to the user's personal plugin directory.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get personal plugin directory.
Returns
A pointer to a statically allocated string containing the personal plugin directory path.

◆ get_plugins_pers_dir_with_version()

WS_DLL_PUBLIC const char * get_plugins_pers_dir_with_version ( const char *  app_env_var_prefix)

Appends VERSION_MAJOR.VERSION_MINOR to the personal plugin directory path.

Constructs the full path to the user's personal plugin directory by appending the current Wireshark major and minor version numbers.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get personal plugin directory.
Returns
A pointer to a statically allocated string containing the versioned personal plugin directory path.

◆ get_profile_dir()

WS_DLL_PUBLIC char * get_profile_dir ( const char *  app_env_var_prefix,
const char *  profilename,
bool  is_global 
)

Gets the directory used to store configuration files for a given profile.

Constructs the full path to the configuration directory associated with the specified profile name. If the profile is global, the path will point to the system-wide profile location; otherwise, it will point to the user's personal profile directory.

The returned string is allocated with g_malloc() and must be freed with g_free() when no longer needed.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
profilenameThe name of the configuration profile.
is_globaltrue if the profile is global, false if it is personal.
Returns
A g_malloc()'d string containing the full path to the profile's configuration directory.

◆ get_profile_name()

WS_DLL_PUBLIC const char * get_profile_name ( void  )

Gets the current configuration profile name used for storing personal configuration files.

Returns the name of the active configuration profile, which determines the location for storing and retrieving personal configuration files.

Returns
A pointer to a statically allocated string containing the profile name.

◆ get_profiles_dir()

WS_DLL_PUBLIC char * get_profiles_dir ( const char *  app_env_var_prefix)

Gets the directory used to store configuration profile directories.

Returns the path to the base directory where configuration profiles are stored. The caller is responsible for freeing the returned string using g_free().

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
Returns
A g_malloc()'d string containing the configuration profiles directory path.

◆ get_progfile_dir()

WS_DLL_PUBLIC const char * get_progfile_dir ( void  )

Get the directory in which the main (Wireshark, TShark, Stratoshark, etc) program resides.

Extcaps should use get_extcap_dir() to get their path.

Returns
The main program file directory.

◆ get_systemfile_dir()

WS_DLL_PUBLIC const char * get_systemfile_dir ( const char *  app_env_var_prefix)

Gets the directory in which system files are stored.

On UNIX-like systems, this typically refers to standard locations such as "/etc". On Windows, where such directories do not exist, the files are retrieved from the Wireshark global configuration and data file directory instead.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get system files directory.
Returns
A pointer to a statically allocated string containing the system file directory path.

◆ has_global_profiles()

WS_DLL_PUBLIC bool has_global_profiles ( const char *  app_env_var_prefix)

Checks whether global configuration profiles are available.

Determines if any global (system-wide) configuration profiles are present and accessible to the application.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
Returns
true if global profiles are available, false otherwise.

◆ is_default_profile()

WS_DLL_PUBLIC bool is_default_profile ( void  )

Checks whether the current configuration profile is the default profile.

Determines if the active profile is the default one, which typically stores user configuration in the standard personal configuration directory.

Returns
true if the current profile is the default profile, false otherwise.

◆ profile_exists()

WS_DLL_PUBLIC bool profile_exists ( const char *  app_env_var_prefix,
const char *  profilename,
bool  global 
)

Checks whether a given configuration profile exists.

Determines if the specified configuration profile is present either in the global or personal profile directories.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
profilenameThe name of the configuration profile to check.
globaltrue to check in the global profiles directory, false to check in the personal profiles directory.
Returns
true if the profile exists, false otherwise.

◆ profile_register_persconffile()

WS_DLL_PUBLIC void profile_register_persconffile ( const char *  filename)

Registers a filename to the personal configuration files storage.

Adds a file to the list of personal configuration files that should be tracked for profile duplication. This is intended for files that are not automatically registered via get_persconffile_path() during startup.

Parameters
filenameThe name of the personal configuration file to register.

◆ profile_store_persconffiles()

WS_DLL_PUBLIC void profile_store_persconffiles ( bool  store)

Enables or disables tracking of personal configuration file names for profile duplication.

When enabled, this function records the names of personal configuration files that should be copied when duplicating a configuration profile.

Parameters
storetrue to begin storing file names, false to stop.

◆ rename_persconffile_profile()

WS_DLL_PUBLIC int rename_persconffile_profile ( const char *  app_env_var_prefix,
const char *  fromname,
const char *  toname,
char **  pf_from_dir_path_return,
char **  pf_to_dir_path_return 
)

Renames the directory for the given configuration profile.

Attempts to rename the configuration profile directory from the specified source name to the target name. If the operation fails, the function returns -1 and sets *pf_from_dir_path_return and/or *pf_to_dir_path_return to the respective source or destination paths involved in the failure. These strings are allocated with g_malloc() and must be freed with g_free() by the caller. On success, the function returns 0.

Parameters
app_env_var_prefixThe prefix for the application environment variable used to get the profiles directory.
fromnameThe current name of the configuration profile.
tonameThe new name to assign to the configuration profile.
pf_from_dir_path_returnPointer to receive the g_malloc()'d source directory path if the rename fails.
pf_to_dir_path_returnPointer to receive the g_malloc()'d destination directory path if the rename fails.
Returns
0 on success, -1 on failure.

◆ running_in_build_directory()

WS_DLL_PUBLIC bool running_in_build_directory ( void  )

Indicates whether Wireshark is running from a build directory.

Returns a boolean flag that signals whether the current execution context is within a build directory.

Returns
true if running from a build directory, false otherwise.

◆ set_persconffile_dir()

WS_DLL_PUBLIC void set_persconffile_dir ( const char *  p)

Sets the path of the personal configuration file directory.

Defines the base directory where personal configuration files will be stored. This overrides any default or previously set location for personal configuration data.

Parameters
pThe path to use as the personal configuration file directory.

◆ set_persdatafile_dir()

WS_DLL_PUBLIC void set_persdatafile_dir ( const char *  p)

Sets the path of the directory in which personal data is stored.

Overrides the default location used for storing personal data files. This allows customization of where personal data is saved, independent of platform defaults.

Parameters
pThe path to use as the personal data directory.

◆ set_profile_name()

WS_DLL_PUBLIC void set_profile_name ( const char *  profilename)

Sets the configuration profile name for storing personal configuration files.

This function defines the active profile name, which determines the location where personal configuration files will be stored and accessed.

Parameters
profilenameThe name of the configuration profile to use.

◆ test_for_directory()

WS_DLL_PUBLIC int test_for_directory ( const char *  path)

Tests whether a given pathname refers to a directory.

Performs a stat() system call on the provided pathname and returns:

  • The errno value if the stat() call fails.
  • EISDIR if the stat() call succeeds and the pathname refers to a directory.
  • 0 if the stat() call succeeds and the pathname refers to a non-directory file.

This function is useful for distinguishing between files and directories, and for detecting stat-related errors.

Parameters
pathThe path to test.
Returns
errno on stat failure, EISDIR if it's a directory, or 0 if it's a non-directory file.

◆ test_for_fifo()

WS_DLL_PUBLIC int test_for_fifo ( const char *  path)

Tests whether a given pathname refers to a FIFO (named pipe).

Performs a stat() system call on the provided pathname and returns:

  • The errno value if the stat() call fails.
  • ESPIPE if the stat() call succeeds and the pathname refers to a FIFO.
  • 0 if the stat() call succeeds and the pathname refers to a non-FIFO file.

This function is useful for identifying named pipes and handling them appropriately in file or stream operations.

Parameters
pathThe path to test.
Returns
errno on stat failure, ESPIPE if it's a FIFO, or 0 if it's a non-FIFO file.

◆ test_for_regular_file()

WS_DLL_PUBLIC bool test_for_regular_file ( const char *  path)

Tests whether a given pathname refers to a regular file.

Performs a stat() system call on the provided pathname and returns true if the call succeeds and the file is a regular file. Symbolic links to regular files are also considered valid, as stat() follows links.

Parameters
pathThe path to test.
Returns
true if the pathname refers to a regular file or a symlink to one, false otherwise.

◆ write_file_binary_mode()

WS_DLL_PUBLIC bool write_file_binary_mode ( const char *  filename,
const void *  content,
size_t  content_len 
)

Writes raw content to a file in binary mode.

Writes the specified content to the given file using binary mode, ensuring compatibility across platforms that differentiate between text and binary file handling. This function does not interpret or modify the content—it writes the raw bytes as-is.

If the write operation fails, the function returns false and displays a simple dialog window with the corresponding error message. On success, it returns true.

Parameters
filenameThe path to the file to write.
contentA pointer to the raw content to be written.
content_lenThe number of bytes to write from the content buffer.
Returns
true on success, false on failure.