2 * Filesystem utility definitions
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 * Default profile name.
31 #define DEFAULT_PROFILE "Default"
35 * Get the pathname of the directory from which the executable came,
36 * and save it for future use. Returns NULL on success, and a
37 * g_mallocated string containing an error on failure.
39 extern char *init_progfile_dir(const char *arg0, int (*main)(int, char **));
42 * Get the directory in which the program resides.
44 extern const char *get_progfile_dir(void);
47 * Get the directory in which plugins are stored; this must not be called
48 * before init_progfile_dir() is called, as they might be stored in a
49 * subdirectory of the program file directory.
51 extern const char *get_plugin_dir(void);
54 * Get the directory in which python plugins are stored; this must not be
55 * called before init_progfile_dir() is called, as they might be stored in a
56 * subdirectory of the program file directory.
58 extern const char *get_wspython_dir(void);
61 * Get the flag indicating whether we're running from a build
64 extern gboolean running_in_build_directory(void);
67 * Get the directory in which global configuration files are
70 extern const char *get_datafile_dir(void);
73 * Construct the path name of a global configuration file, given the
76 * The returned file name was g_malloc()'d so it must be g_free()d when the
77 * caller is done with it.
79 extern char *get_datafile_path(const char *filename);
82 * Get the directory in which files that, at least on UNIX, are
83 * system files (such as "/etc/ethers") are stored; on Windows,
84 * there's no "/etc" directory, so we get them from the Wireshark
85 * global configuration and data file directory.
87 extern const char *get_systemfile_dir(void);
90 * Set the configuration profile name to be used for storing
91 * personal configuration files.
93 extern void set_profile_name(const gchar *profilename);
96 * Get the current configuration profile name used for storing
97 * personal configuration files.
99 extern const char *get_profile_name(void);
102 * Get the directory used to store configuration profile directories.
104 extern const char *get_profiles_dir(void);
107 * Check if given configuration profile exists.
109 extern gboolean profile_exists(const gchar *profilename);
112 * Create a directory for the given configuration profile.
113 * If we attempted to create it, and failed, return -1 and
114 * set "*pf_dir_path_return" to the pathname of the directory we failed
115 * to create (it's g_mallocated, so our caller should free it); otherwise,
118 extern int create_persconffile_profile(const char *profilename,
119 char **pf_dir_path_return);
122 * Delete the directory for the given configuration profile.
123 * If we attempted to delete it, and failed, return -1 and
124 * set "*pf_dir_path_return" to the pathname of the directory we failed
125 * to delete (it's g_mallocated, so our caller should free it); otherwise,
128 extern int delete_persconffile_profile(const char *profilename,
129 char **pf_dir_path_return);
132 * Rename the directory for the given confinguration profile.
134 extern int rename_persconffile_profile(const char *fromname, const char *toname,
135 char **pf_from_dir_path_return,
136 char **pf_to_dir_path_return);
139 * Create the directory that holds personal configuration files, if
140 * necessary. If we attempted to create it, and failed, return -1 and
141 * set "*pf_dir_path_return" to the pathname of the directory we failed
142 * to create (it's g_mallocated, so our caller should free it); otherwise,
145 extern int create_persconffile_dir(char **pf_dir_path_return);
148 * Construct the path name of a personal configuration file, given the
149 * file name. If using configuration profiles this directory will be
150 * used if "from_profile" is TRUE.
152 * On Win32, if "for_writing" is FALSE, we check whether the file exists
153 * and, if not, construct a path name relative to the ".wireshark"
154 * subdirectory of the user's home directory, and check whether that
155 * exists; if it does, we return that, so that configuration files
156 * from earlier versions can be read.
158 * The returned file name was g_malloc()'d so it must be g_free()d when the
159 * caller is done with it.
161 extern char *get_persconffile_path(const char *filename, gboolean from_profile,
162 gboolean for_writing);
165 * Get the (default) directory in which personal data is stored.
167 * On Win32, this is the "My Documents" folder in the personal profile.
168 * On UNIX this is simply the current directory.
170 extern char *get_persdatafile_dir(void);
173 * Construct the path name of a file in $TMP/%TEMP% directory.
174 * Or "/tmp/<filename>" (C:\<filename>) if that fails.
176 * Return value is g_malloced so the caller should g_free it.
178 extern char *get_tempfile_path(const char *filename);
181 * process command line option belonging to the filesystem settings
183 extern int filesystem_opt(int opt, const char *optstr);
186 * Return an error message for UNIX-style errno indications on open or
189 extern const char *file_open_error_message(int err, gboolean for_writing);
192 * Return an error message for UNIX-style errno indications on write
195 extern const char *file_write_error_message(int err);
198 * Given a pathname, return the last component.
200 extern const char *get_basename(const char *);
203 * Given a pathname, return a string containing everything but the
204 * last component. NOTE: this overwrites the pathname handed into
207 extern char *get_dirname(char *);
210 * Given a pathname, return:
212 * the errno, if an attempt to "stat()" the file fails;
214 * EISDIR, if the attempt succeeded and the file turned out
217 * 0, if the attempt succeeded and the file turned out not
220 extern int test_for_directory(const char *);
223 * Given a pathname, return:
225 * the errno, if an attempt to "stat()" the file fails;
227 * ESPIPE, if the attempt succeeded and the file turned out
230 * 0, if the attempt succeeded and the file turned out not
233 extern int test_for_fifo(const char *);
236 extern gboolean deletefile (const char *path);
239 * Check, if file is existing.
241 extern gboolean file_exists(const char *fname);
244 * Check if two filenames are identical (with absolute and relative paths).
246 extern gboolean files_identical(const char *fname1, const char *fname2);
249 * Copy a file in binary mode, for those operating systems that care about
250 * such things. This should be OK for all files, even text files, as
251 * we'll copy the raw bytes, and we don't look at the bytes as we copy
254 * Returns TRUE on success, FALSE on failure. If a failure, it also
255 * displays a simple dialog window with the error message.
257 extern gboolean copy_file_binary_mode(const char *from_filename,
258 const char *to_filename);
262 * utf8 version of getenv, needed to get win32 filename paths
264 extern char *getenv_utf8(const char *varname);
267 #endif /* FILESYSTEM_H */