White space changes.
[obnox/wireshark/wip.git] / epan / filesystem.h
1 /* filesystem.h
2  * Filesystem utility definitions
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef FILESYSTEM_H
26 #define FILESYSTEM_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 /*
33  * Default profile name.
34  */
35 #define DEFAULT_PROFILE      "Default"
36
37
38 /*
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.
42  */
43 extern char *init_progfile_dir(const char *arg0, int (*main)(int, char **));
44
45 /*
46  * Get the directory in which the program resides.
47  */
48 extern const char *get_progfile_dir(void);
49
50 /*
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.
54  */
55 extern const char *get_plugin_dir(void);
56
57 /*
58  * Get the directory in which python plugins are stored; this must not be
59  * called before init_progfile_dir() is called, as they might be stored in a
60  * subdirectory of the program file directory.
61  */
62 extern const char *get_wspython_dir(void);
63
64 /*
65  * Get the flag indicating whether we're running from a build
66  * directory.
67  */
68 extern gboolean running_in_build_directory(void);
69
70 /*
71  * Get the directory in which global configuration files are
72  * stored.
73  */
74 extern const char *get_datafile_dir(void);
75
76 /*
77  * Construct the path name of a global configuration file, given the
78  * file name.
79  *
80  * The returned file name was g_malloc()'d so it must be g_free()d when the
81  * caller is done with it.
82  */
83 extern char *get_datafile_path(const char *filename);
84
85 /*
86  * Get the personal plugin dir.
87  */
88 extern char *get_plugins_pers_dir(void);
89
90 /*
91  * Get the directory in which files that, at least on UNIX, are
92  * system files (such as "/etc/ethers") are stored; on Windows,
93  * there's no "/etc" directory, so we get them from the Wireshark
94  * global configuration and data file directory.
95  */
96 extern const char *get_systemfile_dir(void);
97
98 /*
99  * Set the configuration profile name to be used for storing
100  * personal configuration files.
101  */
102 extern void set_profile_name(const gchar *profilename);
103
104 /*
105  * Get the current configuration profile name used for storing
106  * personal configuration files.
107  */
108 extern const char *get_profile_name(void);
109
110 /*
111  * Check if current profile is default profile.
112  */
113 extern gboolean is_default_profile(void);
114
115 /*
116  * Check if we have global profiles.
117  */
118 extern gboolean has_global_profiles(void);
119
120 /*
121  * Get the directory used to store configuration profile directories.
122  */
123 extern const char *get_profiles_dir(void);
124
125 /*
126  * Get the directory used to store global configuration profile directories.
127  */
128 extern const char *get_global_profiles_dir(void);
129
130
131 /*
132  * Store filenames used for personal config files so we know which
133  * files to copy when duplicate a configuration profile.
134  */
135 extern void profile_store_persconffiles(gboolean store);
136
137 /*
138  * Check if given configuration profile exists.
139  */
140 extern gboolean profile_exists(const gchar *profilename, gboolean global);
141
142 /*
143  * Create a directory for the given configuration profile.
144  * If we attempted to create it, and failed, return -1 and
145  * set "*pf_dir_path_return" to the pathname of the directory we failed
146  * to create (it's g_mallocated, so our caller should free it); otherwise,
147  * return 0.
148  */
149 extern int create_persconffile_profile(const char *profilename,
150                                        char **pf_dir_path_return);
151
152 /*
153  * Delete the directory for the given configuration profile.
154  * If we attempted to delete it, and failed, return -1 and
155  * set "*pf_dir_path_return" to the pathname of the directory we failed
156  * to delete (it's g_mallocated, so our caller should free it); otherwise,
157  * return 0.
158  */
159 extern int delete_persconffile_profile(const char *profilename,
160                                        char **pf_dir_path_return);
161
162 /*
163  * Rename the directory for the given confinguration profile.
164  */
165 extern int rename_persconffile_profile(const char *fromname, const char *toname,
166                                        char **pf_from_dir_path_return,
167                                        char **pf_to_dir_path_return);
168
169 /*
170  * Copy files in one profile to the other.
171  */
172 extern int copy_persconffile_profile(const char *toname, const char *fromname,
173                                      gboolean from_global,
174                                      char **pf_filename_return,
175                                      char **pf_to_dir_path_return,
176                                      char **pf_from_dir_path_return);
177
178 /*
179  * Create the directory that holds personal configuration files, if
180  * necessary.  If we attempted to create it, and failed, return -1 and
181  * set "*pf_dir_path_return" to the pathname of the directory we failed
182  * to create (it's g_mallocated, so our caller should free it); otherwise,
183  * return 0.
184  */
185 extern int create_persconffile_dir(char **pf_dir_path_return);
186
187 /*
188  * Construct the path name of a personal configuration file, given the
189  * file name.  If using configuration profiles this directory will be
190  * used if "from_profile" is TRUE.
191  *
192  * On Win32, if "for_writing" is FALSE, we check whether the file exists
193  * and, if not, construct a path name relative to the ".wireshark"
194  * subdirectory of the user's home directory, and check whether that
195  * exists; if it does, we return that, so that configuration files
196  * from earlier versions can be read.
197  *
198  * The returned file name was g_malloc()'d so it must be g_free()d when the
199  * caller is done with it.
200  */
201 extern char *get_persconffile_path(const char *filename, gboolean from_profile,
202                                    gboolean for_writing);
203
204 /*
205  * Get the (default) directory in which personal data is stored.
206  *
207  * On Win32, this is the "My Documents" folder in the personal profile.
208  * On UNIX this is simply the current directory.
209  */
210 extern const char *get_persdatafile_dir(void);
211
212 /*
213  * Construct the path name of a file in $TMP/%TEMP% directory.
214  * Or "/tmp/<filename>" (C:\<filename>) if that fails.
215  *
216  * Return value is g_malloced so the caller should g_free it.
217  */
218 extern char *get_tempfile_path(const char *filename);
219
220 /*
221  * process command line option belonging to the filesystem settings
222  */
223 extern int filesystem_opt(int opt, const char *optstr);
224
225 /*
226  * Return an error message for UNIX-style errno indications on open or
227  * create operations.
228  */
229 extern const char *file_open_error_message(int err, gboolean for_writing);
230
231 /*
232  * Return an error message for UNIX-style errno indications on write
233  * operations.
234  */
235 extern const char *file_write_error_message(int err);
236
237 /*
238  * Given a pathname, return the last component.
239  */
240 extern const char *get_basename(const char *);
241
242  /*
243   * Given a pathname, return a pointer to the last pathname separator
244   * character in the pathname, or NULL if the pathname contains no
245   * separators.
246   */
247 extern char *find_last_pathname_separator(const char *path);
248
249 /*
250  * Given a pathname, return a string containing everything but the
251  * last component.  NOTE: this overwrites the pathname handed into
252  * it....
253  */
254 extern char *get_dirname(char *);
255
256 /*
257  * Given a pathname, return:
258  *
259  *      the errno, if an attempt to "stat()" the file fails;
260  *
261  *      EISDIR, if the attempt succeeded and the file turned out
262  *      to be a directory;
263  *
264  *      0, if the attempt succeeded and the file turned out not
265  *      to be a directory.
266  */
267 extern int test_for_directory(const char *);
268
269 /*
270  * Given a pathname, return:
271  *
272  *      the errno, if an attempt to "stat()" the file fails;
273  *
274  *      ESPIPE, if the attempt succeeded and the file turned out
275  *      to be a FIFO;
276  *
277  *      0, if the attempt succeeded and the file turned out not
278  *      to be a FIFO.
279  */
280 extern int test_for_fifo(const char *);
281
282 /* Delete a file */
283 extern gboolean deletefile (const char *path);
284
285 /*
286  * Check, if file is existing.
287  */
288 extern gboolean file_exists(const char *fname);
289
290 /*
291  * Check if two filenames are identical (with absolute and relative paths).
292  */
293 extern gboolean files_identical(const char *fname1, const char *fname2);
294
295 /*
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
299  * them.
300  *
301  * Returns TRUE on success, FALSE on failure. If a failure, it also
302  * displays a simple dialog window with the error message.
303  */
304 extern gboolean copy_file_binary_mode(const char *from_filename,
305     const char *to_filename);
306
307 #ifdef __cplusplus
308 }
309 #endif /* __cplusplus */
310
311 #endif /* FILESYSTEM_H */