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