nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 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> /* for _read(), _write(), etc. */
36 #include <gmodule.h>
37 #endif
38  
39 #ifdef HAVE_FCNTL_H
40 #include <fcntl.h> /* for open() */
41 #endif
42  
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h> /* for read(), write(), close(), etc. */
45 #endif
46  
47 #ifdef HAVE_SYS_STAT_H
48 #include <sys/stat.h> /* for stat() and struct stat */
49 #endif
50  
51 /*
52 * Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't
53 * define them either.)
54 *
55 * Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO.
56 */
57 #ifndef S_ISREG
58 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
59 #endif
60 #ifndef S_IFIFO
61 #define S_IFIFO _S_IFIFO
62 #endif
63 #ifndef S_ISFIFO
64 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
65 #endif
66 #ifndef S_ISDIR
67 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
68 #endif
69  
70 #include <stdio.h>
71  
72 #ifdef _WIN32
73  
74 /*
75 * The structure to pass to ws_stat64() and ws_fstat64().
76 */
77 #define ws_statb64 struct _stat64
78  
79 /* Win32 (and Win64): we use UTF-8 for filenames and pathnames throughout
80 * the code, so file functions must convert filenames and pathnames from
81 * UTF-8 to UTF-16 as we use NT Unicode (Win9x - now unsupported - used
82 * locale-based encoding here). Microsoft's UN*X-style wrappers don't
83 * do that - they expect locale-based encodings - so we need our own
84 * wrappers. (We don't use the wrappers from GLib as that would, at
85 * least for the wrappers that return file descriptors or take them
86 * as arguments, require that we use the version of the C runtime with
87 * which the GLib binaries were built, and we can't guarantee to do that.)
88 *
89 * Note also that ws_stdio_rename() uses MoveFileEx() with
90 * MOVEFILE_REPLACE_EXISTING, so that it acts like UN*X rename(),
91 * removing the target if necessary.
92 */
93  
94 WS_DLL_PUBLIC int ws_stdio_open (const gchar *filename, int flags, int mode);
95 WS_DLL_PUBLIC int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
96 WS_DLL_PUBLIC int ws_stdio_mkdir (const gchar *filename, int mode);
97 WS_DLL_PUBLIC int ws_stdio_stat64 (const gchar *filename, ws_statb64 *buf);
98 WS_DLL_PUBLIC int ws_stdio_unlink (const gchar *filename);
99 WS_DLL_PUBLIC int ws_stdio_remove (const gchar *filename);
100  
101 WS_DLL_PUBLIC FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
102 WS_DLL_PUBLIC FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
103  
104 #define ws_open ws_stdio_open
105 #define ws_rename ws_stdio_rename
106 #define ws_mkdir ws_stdio_mkdir
107 #define ws_stat64 ws_stdio_stat64
108 #define ws_unlink ws_stdio_unlink
109 #define ws_remove ws_stdio_remove
110 #define ws_fopen ws_stdio_fopen
111 #define ws_freopen ws_stdio_freopen
112  
113 /*
114 * These routines don't take pathnames, so they don't require
115 * pathname-converting wrappers on Windows.
116 */
117 #define ws_read _read
118 #define ws_write _write
119 #define ws_close _close
120 #define ws_dup _dup
121 #define ws_fstat64 _fstati64 /* use _fstati64 for 64-bit size support */
122 #define ws_lseek64 _lseeki64 /* use _lseeki64 for 64-bit offset support */
123 #define ws_fdopen _fdopen
124 #define ws_fileno _fileno
125 #define ws_isatty _isatty
126 #define ws_getc_unlocked _fgetc_nolock
127  
128 /*
129 * Other CRT functions. getpid probably belongs in sys_util.h or proc_util.h
130 * but neither yet exist.
131 */
132 #define ws_getpid _getpid
133 #define ws_umask _umask
134  
135 /* DLL loading */
136  
137 /** Try to remove the current directory from the DLL search path.
138 * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
139 *
140 * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
141 */
142 WS_DLL_PUBLIC
143 gboolean ws_init_dll_search_path();
144  
145 /** Load a DLL using LoadLibrary.
146 * Only the system and program directories are searched.
147 *
148 * @param library_name The name of the DLL.
149 * @return A handle to the DLL if found, NULL on failure.
150 */
151  
152 WS_DLL_PUBLIC
153 void *ws_load_library(const gchar *library_name);
154  
155 /** Load a DLL using g_module_open.
156 * Only the system and program directories are searched.
157 *
158 * @param module_name The name of the DLL.
159 * @param flags Flags to be passed to g_module_open.
160 * @return A handle to the DLL if found, NULL on failure.
161 */
162 WS_DLL_PUBLIC
163 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
164  
165 /** Create or open a "Wireshark is running" mutex.
166 * Create or open a mutex which signals that Wireshark or its associated
167 * executables is running. Used by the installer to test for a running application.
168 */
169 WS_DLL_PUBLIC void create_app_running_mutex();
170  
171 #else /* _WIN32 */
172  
173 /*
174 * The structure to pass to ws_fstat64().
175 */
176 #define ws_statb64 struct stat
177  
178 /* Not Windows, presumed to be UN*X-compatible */
179 #define ws_open open
180 #define ws_rename rename
181 #define ws_mkdir(dir,mode) mkdir(dir,mode)
182 #define ws_stat64 stat
183 #define ws_unlink unlink
184 #define ws_remove remove
185 #define ws_fopen fopen
186 #define ws_freopen freopen
187  
188 #define ws_read read
189 #define ws_write write
190 #ifdef __cplusplus
191 /*
192 * Just in case this is used in a class with a close method or member.
193 */
194 #define ws_close ::close
195 #else
196 #define ws_close close
197 #endif
198 #define ws_dup dup
199 #define ws_fstat64 fstat /* AC_SYS_LARGEFILE should make off_t 64-bit */
200 #define ws_lseek64 lseek /* AC_SYS_LARGEFILE should make off_t 64-bit */
201 #define ws_fdopen fdopen
202 #define ws_fileno fileno
203 #define ws_isatty isatty
204 #define ws_getc_unlocked getc_unlocked
205 #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
206  
207 /* Other CRT functions */
208 #define ws_getpid getpid
209 #define ws_umask umask
210  
211 #endif /* _WIN32 */
212  
213 /* directory handling */
214 #define WS_DIR GDir
215 #define WS_DIRENT const char
216 #define ws_dir_open g_dir_open
217 #define ws_dir_read_name g_dir_read_name
218 #define ws_dir_get_name(dirent) dirent
219 #define ws_dir_rewind g_dir_rewind
220 #define ws_dir_close g_dir_close
221  
222 /* XXX - remove include "sys/stat.h" from files that include this header */
223 /* XXX - update docs (e.g. README.developer) */
224  
225 #ifdef __cplusplus
226 }
227 #endif /* __cplusplus */
228  
229 #endif /* __FILE_UTIL_H__ */