[filesystem.c] Add a cast to aviod a warning with VisualStudio 2017.
[metze/wireshark/wip.git] / wsutil / filesystem.h
1 /* filesystem.h
2  * Filesystem utility definitions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef FILESYSTEM_H
24 #define FILESYSTEM_H
25
26 #include "ws_symbol_export.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 WS_DLL_PUBLIC char *init_progfile_dir(const char *arg0, int (*function_addr)(int, char **));
44
45 /*
46  * Get the directory in which the program resides.
47  */
48 WS_DLL_PUBLIC 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 WS_DLL_PUBLIC const char *get_plugin_dir(void);
56
57 /*
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.
61  */
62 WS_DLL_PUBLIC const char *get_extcap_dir(void);
63
64 /*
65  * Get the flag indicating whether we're running from a build
66  * directory.
67  */
68 WS_DLL_PUBLIC gboolean running_in_build_directory(void);
69
70 /*
71  * Get the directory in which global configuration files are
72  * stored.
73  */
74 WS_DLL_PUBLIC 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 WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
84
85 /*
86  * Get the personal plugin dir.
87  * Return value is malloced so the caller should g_free() it.
88  */
89 WS_DLL_PUBLIC char *get_plugins_pers_dir(void);
90
91 /*
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.
96  */
97 WS_DLL_PUBLIC const char *get_systemfile_dir(void);
98
99 /*
100  * Set the configuration profile name to be used for storing
101  * personal configuration files.
102  */
103 WS_DLL_PUBLIC void set_profile_name(const gchar *profilename);
104
105 /*
106  * Get the current configuration profile name used for storing
107  * personal configuration files.
108  */
109 WS_DLL_PUBLIC const char *get_profile_name(void);
110
111 /*
112  * Check if current profile is default profile.
113  */
114 WS_DLL_PUBLIC gboolean is_default_profile(void);
115
116 /*
117  * Check if we have global profiles.
118  */
119 WS_DLL_PUBLIC gboolean has_global_profiles(void);
120
121 /*
122  * Get the directory used to store configuration profile directories.
123  * Caller must free the returned string
124  */
125 WS_DLL_PUBLIC char *get_profiles_dir(void);
126
127 /*
128  * Create the directory used to store configuration profile directories.
129  */
130 WS_DLL_PUBLIC int create_profiles_dir(char **pf_dir_path_return);
131
132 /*
133  * Get the directory used to store global configuration profile directories.
134  * Caller must free the returned string
135  */
136 WS_DLL_PUBLIC char *get_global_profiles_dir(void);
137
138
139 /*
140  * Store filenames used for personal config files so we know which
141  * files to copy when duplicate a configuration profile.
142  */
143 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
144
145 /*
146  * Store a list of all personal config files which belongs in a profile.
147  */
148 WS_DLL_PUBLIC void profile_write_info_file(void);
149
150 /*
151  * Check if given configuration profile exists.
152  */
153 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
154
155 /*
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,
160  * return 0.
161  */
162 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
163                                        char **pf_dir_path_return);
164
165 /*
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,
170  * return 0.
171  */
172 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
173                                        char **pf_dir_path_return);
174
175 /*
176  * Rename the directory for the given confinguration profile.
177  */
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);
181
182 /*
183  * Copy files in one profile to the other.
184  */
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);
190
191 /*
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,
196  * return 0.
197  */
198 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
199
200 /*
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.
204  *
205  * The returned file name was g_malloc()'d so it must be g_free()d when the
206  * caller is done with it.
207  */
208 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
209
210 /*
211  * Set the path of the personal configuration file directory.
212  */
213 WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
214
215 /*
216  * Get the (default) directory in which personal data is stored.
217  *
218  * On Win32, this is the "My Documents" folder in the personal profile.
219  * On UNIX this is simply the current directory.
220  */
221 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
222
223 /*
224  * Set the path of the directory in which personal data is stored.
225  */
226 WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
227
228 /*
229  * Return an error message for UNIX-style errno indications on open or
230  * create operations.
231  */
232 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
233
234 /*
235  * Return an error message for UNIX-style errno indications on write
236  * operations.
237  */
238 WS_DLL_PUBLIC const char *file_write_error_message(int err);
239
240 /*
241  * Given a pathname, return the last component.
242  */
243 WS_DLL_PUBLIC const char *get_basename(const char *);
244
245  /*
246   * Given a pathname, return a pointer to the last pathname separator
247   * character in the pathname, or NULL if the pathname contains no
248   * separators.
249   */
250 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
251
252 /*
253  * Given a pathname, return a string containing everything but the
254  * last component.  NOTE: this overwrites the pathname handed into
255  * it....
256  */
257 WS_DLL_PUBLIC char *get_dirname(char *);
258
259 /*
260  * Given a pathname, return:
261  *
262  *      the errno, if an attempt to "stat()" the file fails;
263  *
264  *      EISDIR, if the attempt succeeded and the file turned out
265  *      to be a directory;
266  *
267  *      0, if the attempt succeeded and the file turned out not
268  *      to be a directory.
269  */
270 WS_DLL_PUBLIC int test_for_directory(const char *);
271
272 /*
273  * Given a pathname, return:
274  *
275  *      the errno, if an attempt to "stat()" the file fails;
276  *
277  *      ESPIPE, if the attempt succeeded and the file turned out
278  *      to be a FIFO;
279  *
280  *      0, if the attempt succeeded and the file turned out not
281  *      to be a FIFO.
282  */
283 WS_DLL_PUBLIC int test_for_fifo(const char *);
284
285 /*
286  * Check, if file is existing.
287  */
288 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
289
290 /*
291  * Check if two filenames are identical (with absolute and relative paths).
292  */
293 WS_DLL_PUBLIC 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 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
305     const char *to_filename);
306
307
308 /*
309  * Given a filename return a filesystem URL. Relative paths are prefixed with
310  * the datafile directory path.
311  *
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().
316  */
317 WS_DLL_PUBLIC gchar* data_file_url(const gchar *filename);
318
319 /*
320  * Free the internal structtures
321  */
322 WS_DLL_PUBLIC void free_progdirs(void);
323
324 #ifdef __cplusplus
325 }
326 #endif /* __cplusplus */
327
328 #endif /* FILESYSTEM_H */