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 (*function_addr)(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.
123 * Caller must free the returned string
125 WS_DLL_PUBLIC char *get_profiles_dir(void);
128 * Create the directory used to store configuration profile directories.
130 WS_DLL_PUBLIC int create_profiles_dir(char **pf_dir_path_return);
133 * Get the directory used to store global configuration profile directories.
134 * Caller must free the returned string
136 WS_DLL_PUBLIC char *get_global_profiles_dir(void);
140 * Store filenames used for personal config files so we know which
141 * files to copy when duplicate a configuration profile.
143 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
146 * Store a list of all personal config files which belongs in a profile.
148 WS_DLL_PUBLIC void profile_write_info_file(void);
151 * Check if given configuration profile exists.
153 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
156 * Create a directory for the given configuration profile.
157 * If we attempted to create it, and failed, return -1 and
158 * set "*pf_dir_path_return" to the pathname of the directory we failed
159 * to create (it's g_mallocated, so our caller should free it); otherwise,
162 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
163 char **pf_dir_path_return);
166 * Delete the directory for the given configuration profile.
167 * If we attempted to delete it, and failed, return -1 and
168 * set "*pf_dir_path_return" to the pathname of the directory we failed
169 * to delete (it's g_mallocated, so our caller should free it); otherwise,
172 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
173 char **pf_dir_path_return);
176 * Rename the directory for the given confinguration profile.
178 WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
179 char **pf_from_dir_path_return,
180 char **pf_to_dir_path_return);
183 * Copy files in one profile to the other.
185 WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
186 gboolean from_global,
187 char **pf_filename_return,
188 char **pf_to_dir_path_return,
189 char **pf_from_dir_path_return);
192 * Create the directory that holds personal configuration files, if
193 * necessary. If we attempted to create it, and failed, return -1 and
194 * set "*pf_dir_path_return" to the pathname of the directory we failed
195 * to create (it's g_mallocated, so our caller should free it); otherwise,
198 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
201 * Construct the path name of a personal configuration file, given the
202 * file name. If using configuration profiles this directory will be
203 * used if "from_profile" is TRUE.
205 * The returned file name was g_malloc()'d so it must be g_free()d when the
206 * caller is done with it.
208 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
211 * Set the path of the personal configuration file directory.
213 WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
216 * Get the (default) directory in which personal data is stored.
218 * On Win32, this is the "My Documents" folder in the personal profile.
219 * On UNIX this is simply the current directory.
221 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
224 * Set the path of the directory in which personal data is stored.
226 WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
229 * Return an error message for UNIX-style errno indications on open or
232 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
235 * Return an error message for UNIX-style errno indications on write
238 WS_DLL_PUBLIC const char *file_write_error_message(int err);
241 * Given a pathname, return the last component.
243 WS_DLL_PUBLIC const char *get_basename(const char *);
246 * Given a pathname, return a pointer to the last pathname separator
247 * character in the pathname, or NULL if the pathname contains no
250 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
253 * Given a pathname, return a string containing everything but the
254 * last component. NOTE: this overwrites the pathname handed into
257 WS_DLL_PUBLIC char *get_dirname(char *);
260 * Given a pathname, return:
262 * the errno, if an attempt to "stat()" the file fails;
264 * EISDIR, if the attempt succeeded and the file turned out
267 * 0, if the attempt succeeded and the file turned out not
270 WS_DLL_PUBLIC int test_for_directory(const char *);
273 * Given a pathname, return:
275 * the errno, if an attempt to "stat()" the file fails;
277 * ESPIPE, if the attempt succeeded and the file turned out
280 * 0, if the attempt succeeded and the file turned out not
283 WS_DLL_PUBLIC int test_for_fifo(const char *);
286 * Check, if file is existing.
288 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
291 * Check if two filenames are identical (with absolute and relative paths).
293 WS_DLL_PUBLIC gboolean files_identical(const char *fname1, const char *fname2);
296 * Copy a file in binary mode, for those operating systems that care about
297 * such things. This should be OK for all files, even text files, as
298 * we'll copy the raw bytes, and we don't look at the bytes as we copy
301 * Returns TRUE on success, FALSE on failure. If a failure, it also
302 * displays a simple dialog window with the error message.
304 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
305 const char *to_filename);
309 * Given a filename return a filesystem URL. Relative paths are prefixed with
310 * the datafile directory path.
312 * @param filename A file name or path. Relative paths will be prefixed with
313 * the data file directory path.
314 * @return A filesystem URL for the file or NULL on failure. A non-NULL return
315 * value must be freed with g_free().
317 WS_DLL_PUBLIC gchar* data_file_url(const gchar *filename);
320 * Free the internal structtures
322 WS_DLL_PUBLIC void free_progdirs(void);
326 #endif /* __cplusplus */
328 #endif /* FILESYSTEM_H */