2 * File utility definitions
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
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.
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.
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.
23 #ifndef __FILE_UTIL_H__
24 #define __FILE_UTIL_H__
26 #include "ws_symbol_export.h"
30 #endif /* __cplusplus */
39 #ifdef HAVE_SYS_STAT_H
47 * The structure to pass to ws_stat64() and ws_fstat64().
49 #define ws_statb64 struct _stat64
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.)
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.
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);
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);
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
88 * These routines don't take pathnames, so they don't require
89 * pathname-converting wrappers on Windows.
92 #define ws_write _write
93 #define ws_close _close
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
101 /** Try to remove the current directory from the DLL search path.
102 * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
104 * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
107 gboolean ws_init_dll_search_path();
109 /** Load a DLL using LoadLibrary.
110 * Only the system and program directories are searched.
112 * @param library_name The name of the DLL.
113 * @return A handle to the DLL if found, NULL on failure.
117 void *ws_load_library(gchar *library_name);
119 /** Load a DLL using g_module_open.
120 * Only the system and program directories are searched.
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.
127 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
130 * utf8 version of getenv, needed to get win32 filename paths
132 WS_DLL_PUBLIC char *getenv_utf8(const char *varname);
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.
138 WS_DLL_PUBLIC void create_app_running_mutex();
143 * The structure to pass to ws_fstat64().
145 #define ws_statb64 struct stat
147 /* Not Windows, presumed to be UN*X-compatible */
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
158 #define ws_write write
159 #define ws_close close
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() */
168 /* directory handling */
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
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) */
184 #endif /* __cplusplus */
186 #endif /* __FILE_UTIL_H__ */