2 * Filesystem utility definitions
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "ws_symbol_export.h"
30 #endif /* __cplusplus */
33 * Default profile name.
35 #define DEFAULT_PROFILE "Default"
39 * Get the pathname of the directory from which the executable came,
40 * and save it for future use. Returns NULL on success, and a
41 * g_mallocated string containing an error on failure.
43 WS_DLL_PUBLIC char *init_progfile_dir(const char *arg0, int (*main)(int, char **));
46 * Get the directory in which the program resides.
48 WS_DLL_PUBLIC const char *get_progfile_dir(void);
51 * Get the directory in which plugins are stored; this must not be called
52 * before init_progfile_dir() is called, as they might be stored in a
53 * subdirectory of the program file directory.
55 WS_DLL_PUBLIC const char *get_plugin_dir(void);
58 * Get the directory in which extcap hooks are stored; this must not be called
59 * before init_progfile_dir() is called, as they might be stored in a
60 * subdirectory of the program file directory.
62 WS_DLL_PUBLIC const char *get_extcap_dir(void);
65 * Get the flag indicating whether we're running from a build
68 WS_DLL_PUBLIC gboolean running_in_build_directory(void);
71 * Get the directory in which global configuration files are
74 WS_DLL_PUBLIC const char *get_datafile_dir(void);
77 * Construct the path name of a global configuration file, given the
80 * The returned file name was g_malloc()'d so it must be g_free()d when the
81 * caller is done with it.
83 WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
86 * Get the personal plugin dir.
87 * Return value is malloced so the caller should g_free() it.
89 WS_DLL_PUBLIC char *get_plugins_pers_dir(void);
92 * Get the directory in which files that, at least on UNIX, are
93 * system files (such as "/etc/ethers") are stored; on Windows,
94 * there's no "/etc" directory, so we get them from the Wireshark
95 * global configuration and data file directory.
97 WS_DLL_PUBLIC const char *get_systemfile_dir(void);
100 * Set the configuration profile name to be used for storing
101 * personal configuration files.
103 WS_DLL_PUBLIC void set_profile_name(const gchar *profilename);
106 * Get the current configuration profile name used for storing
107 * personal configuration files.
109 WS_DLL_PUBLIC const char *get_profile_name(void);
112 * Check if current profile is default profile.
114 WS_DLL_PUBLIC gboolean is_default_profile(void);
117 * Check if we have global profiles.
119 WS_DLL_PUBLIC gboolean has_global_profiles(void);
122 * Get the directory used to store configuration profile directories.
124 WS_DLL_PUBLIC const char *get_profiles_dir(void);
127 * Get the directory used to store global configuration profile directories.
129 WS_DLL_PUBLIC const char *get_global_profiles_dir(void);
133 * Store filenames used for personal config files so we know which
134 * files to copy when duplicate a configuration profile.
136 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
139 * Check if given configuration profile exists.
141 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
144 * Create a directory for the given configuration profile.
145 * If we attempted to create it, and failed, return -1 and
146 * set "*pf_dir_path_return" to the pathname of the directory we failed
147 * to create (it's g_mallocated, so our caller should free it); otherwise,
150 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
151 char **pf_dir_path_return);
154 * Delete the directory for the given configuration profile.
155 * If we attempted to delete it, and failed, return -1 and
156 * set "*pf_dir_path_return" to the pathname of the directory we failed
157 * to delete (it's g_mallocated, so our caller should free it); otherwise,
160 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
161 char **pf_dir_path_return);
164 * Rename the directory for the given confinguration profile.
166 WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
167 char **pf_from_dir_path_return,
168 char **pf_to_dir_path_return);
171 * Copy files in one profile to the other.
173 WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
174 gboolean from_global,
175 char **pf_filename_return,
176 char **pf_to_dir_path_return,
177 char **pf_from_dir_path_return);
180 * Create the directory that holds personal configuration files, if
181 * necessary. If we attempted to create it, and failed, return -1 and
182 * set "*pf_dir_path_return" to the pathname of the directory we failed
183 * to create (it's g_mallocated, so our caller should free it); otherwise,
186 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
189 * Construct the path name of a personal configuration file, given the
190 * file name. If using configuration profiles this directory will be
191 * used if "from_profile" is TRUE.
193 * The returned file name was g_malloc()'d so it must be g_free()d when the
194 * caller is done with it.
196 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
199 * Set the path of the personal configuration file directory.
201 WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
204 * Get the (default) directory in which personal data is stored.
206 * On Win32, this is the "My Documents" folder in the personal profile.
207 * On UNIX this is simply the current directory.
209 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
212 * Set the path of the directory in which personal data is stored.
214 WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
217 * Return an error message for UNIX-style errno indications on open or
220 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
223 * Return an error message for UNIX-style errno indications on write
226 WS_DLL_PUBLIC const char *file_write_error_message(int err);
229 * Given a pathname, return the last component.
231 WS_DLL_PUBLIC const char *get_basename(const char *);
234 * Given a pathname, return a pointer to the last pathname separator
235 * character in the pathname, or NULL if the pathname contains no
238 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
241 * Given a pathname, return a string containing everything but the
242 * last component. NOTE: this overwrites the pathname handed into
245 WS_DLL_PUBLIC char *get_dirname(char *);
248 * Given a pathname, return:
250 * the errno, if an attempt to "stat()" the file fails;
252 * EISDIR, if the attempt succeeded and the file turned out
255 * 0, if the attempt succeeded and the file turned out not
258 WS_DLL_PUBLIC int test_for_directory(const char *);
261 * Given a pathname, return:
263 * the errno, if an attempt to "stat()" the file fails;
265 * ESPIPE, if the attempt succeeded and the file turned out
268 * 0, if the attempt succeeded and the file turned out not
271 WS_DLL_PUBLIC int test_for_fifo(const char *);
274 * Check, if file is existing.
276 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
279 * Check if two filenames are identical (with absolute and relative paths).
281 WS_DLL_PUBLIC gboolean files_identical(const char *fname1, const char *fname2);
284 * Copy a file in binary mode, for those operating systems that care about
285 * such things. This should be OK for all files, even text files, as
286 * we'll copy the raw bytes, and we don't look at the bytes as we copy
289 * Returns TRUE on success, FALSE on failure. If a failure, it also
290 * displays a simple dialog window with the error message.
292 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
293 const char *to_filename);
297 #endif /* __cplusplus */
299 #endif /* FILESYSTEM_H */