CPMConnect: unify version handling
[wireshark-wip.git] / epan / filesystem.h
blob6b76bab4fc59a2ba8c91af0ae3246a64170e9d82
1 /* filesystem.h
2 * Filesystem utility definitions
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef FILESYSTEM_H
26 #define FILESYSTEM_H
28 #include "ws_symbol_export.h"
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
35 * Default profile name.
37 #define DEFAULT_PROFILE "Default"
41 * Get the pathname of the directory from which the executable came,
42 * and save it for future use. Returns NULL on success, and a
43 * g_mallocated string containing an error on failure.
45 WS_DLL_PUBLIC char *init_progfile_dir(const char *arg0, int (*main)(int, char **));
48 * Get the directory in which the program resides.
50 WS_DLL_PUBLIC const char *get_progfile_dir(void);
53 * Get the directory in which plugins are stored; this must not be called
54 * before init_progfile_dir() is called, as they might be stored in a
55 * subdirectory of the program file directory.
57 WS_DLL_PUBLIC const char *get_plugin_dir(void);
60 * Get the directory in which python plugins are stored; this must not be
61 * called before init_progfile_dir() is called, as they might be stored in a
62 * subdirectory of the program file directory.
64 WS_DLL_PUBLIC const char *get_wspython_dir(void);
67 * Get the flag indicating whether we're running from a build
68 * directory.
70 WS_DLL_PUBLIC gboolean running_in_build_directory(void);
73 * Get the directory in which global configuration files are
74 * stored.
76 WS_DLL_PUBLIC const char *get_datafile_dir(void);
79 * Construct the path name of a global configuration file, given the
80 * file name.
82 * The returned file name was g_malloc()'d so it must be g_free()d when the
83 * caller is done with it.
85 WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
88 * Get the personal plugin dir.
90 WS_DLL_PUBLIC char *get_plugins_pers_dir(void);
93 * Get the directory in which files that, at least on UNIX, are
94 * system files (such as "/etc/ethers") are stored; on Windows,
95 * there's no "/etc" directory, so we get them from the Wireshark
96 * global configuration and data file directory.
98 WS_DLL_PUBLIC const char *get_systemfile_dir(void);
101 * Set the configuration profile name to be used for storing
102 * personal configuration files.
104 WS_DLL_PUBLIC void set_profile_name(const gchar *profilename);
107 * Get the current configuration profile name used for storing
108 * personal configuration files.
110 WS_DLL_PUBLIC const char *get_profile_name(void);
113 * Check if current profile is default profile.
115 WS_DLL_PUBLIC gboolean is_default_profile(void);
118 * Check if we have global profiles.
120 WS_DLL_PUBLIC gboolean has_global_profiles(void);
123 * Get the directory used to store configuration profile directories.
125 WS_DLL_PUBLIC const char *get_profiles_dir(void);
128 * Get the directory used to store global configuration profile directories.
130 WS_DLL_PUBLIC const char *get_global_profiles_dir(void);
134 * Store filenames used for personal config files so we know which
135 * files to copy when duplicate a configuration profile.
137 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
140 * Check if given configuration profile exists.
142 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
145 * Create a directory for the given configuration profile.
146 * If we attempted to create it, and failed, return -1 and
147 * set "*pf_dir_path_return" to the pathname of the directory we failed
148 * to create (it's g_mallocated, so our caller should free it); otherwise,
149 * return 0.
151 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
152 char **pf_dir_path_return);
155 * Delete the directory for the given configuration profile.
156 * If we attempted to delete it, and failed, return -1 and
157 * set "*pf_dir_path_return" to the pathname of the directory we failed
158 * to delete (it's g_mallocated, so our caller should free it); otherwise,
159 * return 0.
161 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
162 char **pf_dir_path_return);
165 * Rename the directory for the given confinguration profile.
167 WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
168 char **pf_from_dir_path_return,
169 char **pf_to_dir_path_return);
172 * Copy files in one profile to the other.
174 WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
175 gboolean from_global,
176 char **pf_filename_return,
177 char **pf_to_dir_path_return,
178 char **pf_from_dir_path_return);
181 * Create the directory that holds personal configuration files, if
182 * necessary. If we attempted to create it, and failed, return -1 and
183 * set "*pf_dir_path_return" to the pathname of the directory we failed
184 * to create (it's g_mallocated, so our caller should free it); otherwise,
185 * return 0.
187 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
190 * Construct the path name of a personal configuration file, given the
191 * file name. If using configuration profiles this directory will be
192 * used if "from_profile" is TRUE.
194 * The returned file name was g_malloc()'d so it must be g_free()d when the
195 * caller is done with it.
197 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
200 * Get the (default) directory in which personal data is stored.
202 * On Win32, this is the "My Documents" folder in the personal profile.
203 * On UNIX this is simply the current directory.
205 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
208 * Construct the path name of a file in $TMP/%TEMP% directory.
209 * Or "/tmp/<filename>" (C:\<filename>) if that fails.
211 * Return value is g_malloced so the caller should g_free it.
213 WS_DLL_PUBLIC char *get_tempfile_path(const char *filename);
216 * process command line option belonging to the filesystem settings
218 WS_DLL_PUBLIC int filesystem_opt(int opt, const char *optstr);
221 * Return an error message for UNIX-style errno indications on open or
222 * create operations.
224 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
227 * Return an error message for UNIX-style errno indications on write
228 * operations.
230 WS_DLL_PUBLIC const char *file_write_error_message(int err);
233 * Given a pathname, return the last component.
235 WS_DLL_PUBLIC const char *get_basename(const char *);
238 * Given a pathname, return a pointer to the last pathname separator
239 * character in the pathname, or NULL if the pathname contains no
240 * separators.
242 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
245 * Given a pathname, return a string containing everything but the
246 * last component. NOTE: this overwrites the pathname handed into
247 * it....
249 WS_DLL_PUBLIC char *get_dirname(char *);
252 * Given a pathname, return:
254 * the errno, if an attempt to "stat()" the file fails;
256 * EISDIR, if the attempt succeeded and the file turned out
257 * to be a directory;
259 * 0, if the attempt succeeded and the file turned out not
260 * to be a directory.
262 WS_DLL_PUBLIC int test_for_directory(const char *);
265 * Given a pathname, return:
267 * the errno, if an attempt to "stat()" the file fails;
269 * ESPIPE, if the attempt succeeded and the file turned out
270 * to be a FIFO;
272 * 0, if the attempt succeeded and the file turned out not
273 * to be a FIFO.
275 WS_DLL_PUBLIC int test_for_fifo(const char *);
277 /* Delete a file */
278 WS_DLL_PUBLIC gboolean deletefile (const char *path);
281 * Check, if file is existing.
283 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
286 * Check if two filenames are identical (with absolute and relative paths).
288 WS_DLL_PUBLIC gboolean files_identical(const char *fname1, const char *fname2);
291 * Copy a file in binary mode, for those operating systems that care about
292 * such things. This should be OK for all files, even text files, as
293 * we'll copy the raw bytes, and we don't look at the bytes as we copy
294 * them.
296 * Returns TRUE on success, FALSE on failure. If a failure, it also
297 * displays a simple dialog window with the error message.
299 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
300 const char *to_filename);
302 #ifdef __cplusplus
304 #endif /* __cplusplus */
306 #endif /* FILESYSTEM_H */