Try to improve the "Kerberos requested but not OpenSSL" message.
[jelmer/wireshark.git] / wsutil / file_util.h
1 /* file_util.h
2  * File 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 __FILE_UTIL_H__
24 #define __FILE_UTIL_H__
25
26 #include "ws_symbol_export.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <glib.h>
33
34 #ifdef _WIN32
35 #include <io.h>
36 #include <gmodule.h>
37 #endif
38
39 #ifdef HAVE_SYS_STAT_H
40 #include <sys/stat.h>
41 #endif
42
43
44 #ifdef _WIN32
45
46 /*
47  * The structure to pass to ws_stat64() and ws_fstat64().
48  */
49 #define ws_statb64      struct _stat64
50
51 /*  Win32 (and Win64): we use UTF-8 for filenames and pathnames throughout
52  *  the code, so file functions must convert filenames and pathnames from
53  *  UTF-8 to UTF-16 as we use NT Unicode (Win9x - now unsupported - used
54  *  locale-based encoding here).  Microsoft's UN*X-style wrappers don't
55  *  do that - they expect locale-based encodings - so we need our own
56  *  wrappers.  (We don't use the wrappers from GLib as that would, at
57  *  least for the wrappers that return file descriptors or take them
58  *  as arguments, require that we use the version of the C runtime with
59  *  which the GLib binaries were built, and we can't guarantee to do that.)
60  *
61  *  Note also that ws_stdio_rename() uses MoveFileEx() with
62  *  MOVEFILE_REPLACE_EXISTING, so that it acts like UN*X rename(),
63  *  removing the target if necessary.
64  */
65
66 #include <stdio.h>
67
68 WS_DLL_PUBLIC int ws_stdio_open (const gchar *filename, int flags, int mode);
69 WS_DLL_PUBLIC int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
70 WS_DLL_PUBLIC int ws_stdio_mkdir (const gchar *filename, int mode);
71 WS_DLL_PUBLIC int ws_stdio_stat64 (const gchar *filename, ws_statb64 *buf);
72 WS_DLL_PUBLIC int ws_stdio_unlink (const gchar *filename);
73 WS_DLL_PUBLIC int ws_stdio_remove (const gchar *filename);
74
75 WS_DLL_PUBLIC FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
76 WS_DLL_PUBLIC FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
77
78 #define ws_open         ws_stdio_open
79 #define ws_rename       ws_stdio_rename
80 #define ws_mkdir        ws_stdio_mkdir
81 #define ws_stat64       ws_stdio_stat64
82 #define ws_unlink       ws_stdio_unlink
83 #define ws_remove       ws_stdio_remove
84 #define ws_fopen        ws_stdio_fopen
85 #define ws_freopen      ws_stdio_freopen
86
87 /*
88  * These routines don't take pathnames, so they don't require
89  * pathname-converting wrappers on Windows.
90  */
91 #define ws_read    _read
92 #define ws_write   _write
93 #define ws_close   _close
94 #define ws_dup     _dup
95 #define ws_fstat64 _fstati64    /* use _fstati64 for 64-bit size support */
96 #define ws_lseek64 _lseeki64    /* use _lseeki64 for 64-bit offset support */
97 #define ws_fdopen  _fdopen
98
99 /* DLL loading */
100
101 /** Try to remove the current directory from the DLL search path.
102  * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
103  *
104  * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
105  */
106 WS_DLL_PUBLIC
107 gboolean ws_init_dll_search_path();
108
109 /** Load a DLL using LoadLibrary.
110  * Only the system and program directories are searched.
111  *
112  * @param library_name The name of the DLL.
113  * @return A handle to the DLL if found, NULL on failure.
114  */
115
116 WS_DLL_PUBLIC
117 void *ws_load_library(gchar *library_name);
118
119 /** Load a DLL using g_module_open.
120  * Only the system and program directories are searched.
121  *
122  * @param module_name The name of the DLL.
123  * @param flags Flags to be passed to g_module_open.
124  * @return A handle to the DLL if found, NULL on failure.
125  */
126 WS_DLL_PUBLIC
127 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
128
129 /*
130  * utf8 version of getenv, needed to get win32 filename paths
131  */
132 WS_DLL_PUBLIC char *getenv_utf8(const char *varname);
133
134 /** Create or open a "Wireshark is running" mutex.
135  * Create or open a mutex which signals that Wireshark or its associated
136  * executables is running. Used by the installer to test for a running application.
137  */
138 WS_DLL_PUBLIC void create_app_running_mutex();
139
140 #else   /* _WIN32 */
141
142 /*
143  * The structure to pass to ws_fstat64().
144  */
145 #define ws_statb64      struct stat
146
147 /* Not Windows, presumed to be UN*X-compatible */
148 #define ws_open                 open
149 #define ws_rename               rename
150 #define ws_mkdir(dir,mode)      mkdir(dir,mode)
151 #define ws_stat64               stat
152 #define ws_unlink               unlink
153 #define ws_remove               remove
154 #define ws_fopen                fopen
155 #define ws_freopen              freopen
156
157 #define ws_read    read
158 #define ws_write   write
159 #define ws_close   close
160 #define ws_dup     dup
161 #define ws_fstat64 fstat        /* AC_SYS_LARGEFILE should make off_t 64-bit */
162 #define ws_lseek64 lseek        /* AC_SYS_LARGEFILE should make off_t 64-bit */
163 #define ws_fdopen  fdopen
164 #define O_BINARY   0            /* Win32 needs the O_BINARY flag for open() */
165
166 #endif /* _WIN32 */
167
168 /* directory handling */
169 #define WS_DIR                          GDir
170 #define WS_DIRENT                       const char
171 #define ws_dir_open                     g_dir_open
172 #define ws_dir_read_name                g_dir_read_name
173 #define ws_dir_get_name(dirent)         dirent
174 #define ws_dir_rewind                   g_dir_rewind
175 #define ws_dir_close                    g_dir_close
176
177 /* XXX - remove include "dirent.h" */
178 /* XXX - remove include "direct.h" */
179 /* XXX - remove include "sys/stat.h" */
180 /* XXX - update docs (e.g. README.developer) */
181
182 #ifdef __cplusplus
183 }
184 #endif /* __cplusplus */
185
186 #endif /* __FILE_UTIL_H__ */