strptime.c needs ctype.h.
[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 (*main)(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  */
124 WS_DLL_PUBLIC const char *get_profiles_dir(void);
125
126 /*
127  * Get the directory used to store global configuration profile directories.
128  */
129 WS_DLL_PUBLIC const char *get_global_profiles_dir(void);
130
131
132 /*
133  * Store filenames used for personal config files so we know which
134  * files to copy when duplicate a configuration profile.
135  */
136 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
137
138 /*
139  * Check if given configuration profile exists.
140  */
141 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
142
143 /*
144  * Create a directory for the given configuration profile.
145  * If we attempted to create it, and failed, return -1 and
146  * set "*pf_dir_path_return" to the pathname of the directory we failed
147  * to create (it's g_mallocated, so our caller should free it); otherwise,
148  * return 0.
149  */
150 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
151                                        char **pf_dir_path_return);
152
153 /*
154  * Delete the directory for the given configuration profile.
155  * If we attempted to delete it, and failed, return -1 and
156  * set "*pf_dir_path_return" to the pathname of the directory we failed
157  * to delete (it's g_mallocated, so our caller should free it); otherwise,
158  * return 0.
159  */
160 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
161                                        char **pf_dir_path_return);
162
163 /*
164  * Rename the directory for the given confinguration profile.
165  */
166 WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
167                                        char **pf_from_dir_path_return,
168                                        char **pf_to_dir_path_return);
169
170 /*
171  * Copy files in one profile to the other.
172  */
173 WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
174                                      gboolean from_global,
175                                      char **pf_filename_return,
176                                      char **pf_to_dir_path_return,
177                                      char **pf_from_dir_path_return);
178
179 /*
180  * Create the directory that holds personal configuration files, if
181  * necessary.  If we attempted to create it, and failed, return -1 and
182  * set "*pf_dir_path_return" to the pathname of the directory we failed
183  * to create (it's g_mallocated, so our caller should free it); otherwise,
184  * return 0.
185  */
186 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
187
188 /*
189  * Construct the path name of a personal configuration file, given the
190  * file name.  If using configuration profiles this directory will be
191  * used if "from_profile" is TRUE.
192  *
193  * The returned file name was g_malloc()'d so it must be g_free()d when the
194  * caller is done with it.
195  */
196 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
197
198 /*
199  * Set the path of the personal configuration file directory.
200  */
201 WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
202
203 /*
204  * Get the (default) directory in which personal data is stored.
205  *
206  * On Win32, this is the "My Documents" folder in the personal profile.
207  * On UNIX this is simply the current directory.
208  */
209 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
210
211 /*
212  * Set the path of the directory in which personal data is stored.
213  */
214 WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
215
216 /*
217  * Return an error message for UNIX-style errno indications on open or
218  * create operations.
219  */
220 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
221
222 /*
223  * Return an error message for UNIX-style errno indications on write
224  * operations.
225  */
226 WS_DLL_PUBLIC const char *file_write_error_message(int err);
227
228 /*
229  * Given a pathname, return the last component.
230  */
231 WS_DLL_PUBLIC const char *get_basename(const char *);
232
233  /*
234   * Given a pathname, return a pointer to the last pathname separator
235   * character in the pathname, or NULL if the pathname contains no
236   * separators.
237   */
238 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
239
240 /*
241  * Given a pathname, return a string containing everything but the
242  * last component.  NOTE: this overwrites the pathname handed into
243  * it....
244  */
245 WS_DLL_PUBLIC char *get_dirname(char *);
246
247 /*
248  * Given a pathname, return:
249  *
250  *      the errno, if an attempt to "stat()" the file fails;
251  *
252  *      EISDIR, if the attempt succeeded and the file turned out
253  *      to be a directory;
254  *
255  *      0, if the attempt succeeded and the file turned out not
256  *      to be a directory.
257  */
258 WS_DLL_PUBLIC int test_for_directory(const char *);
259
260 /*
261  * Given a pathname, return:
262  *
263  *      the errno, if an attempt to "stat()" the file fails;
264  *
265  *      ESPIPE, if the attempt succeeded and the file turned out
266  *      to be a FIFO;
267  *
268  *      0, if the attempt succeeded and the file turned out not
269  *      to be a FIFO.
270  */
271 WS_DLL_PUBLIC int test_for_fifo(const char *);
272
273 /*
274  * Check, if file is existing.
275  */
276 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
277
278 /*
279  * Check if two filenames are identical (with absolute and relative paths).
280  */
281 WS_DLL_PUBLIC gboolean files_identical(const char *fname1, const char *fname2);
282
283 /*
284  * Copy a file in binary mode, for those operating systems that care about
285  * such things.  This should be OK for all files, even text files, as
286  * we'll copy the raw bytes, and we don't look at the bytes as we copy
287  * them.
288  *
289  * Returns TRUE on success, FALSE on failure. If a failure, it also
290  * displays a simple dialog window with the error message.
291  */
292 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
293     const char *to_filename);
294
295 #ifdef __cplusplus
296 }
297 #endif /* __cplusplus */
298
299 #endif /* FILESYSTEM_H */