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