2 * File utility definitions
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
25 #ifndef __FILE_UTIL_H__
26 #define __FILE_UTIL_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 extern int ws_stdio_open (const gchar *filename, int flags, int mode);
69 extern int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
70 extern int ws_stdio_mkdir (const gchar *filename, int mode);
71 extern int ws_stdio_stat64 (const gchar *filename, ws_statb64 *buf);
72 extern int ws_stdio_unlink (const gchar *filename);
73 extern int ws_stdio_remove (const gchar *filename);
75 extern FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
76 extern 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 */
100 /** Try to remove the current directory from the DLL search path.
101 * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
103 * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
105 gboolean ws_init_dll_search_path();
107 /** Load a DLL using LoadLibrary.
108 * Only the system and program directories are searched.
110 * @param library_name The name of the DLL.
111 * @return A handle to the DLL if found, NULL on failure.
114 void *ws_load_library(gchar *library_name);
115 /** Load a DLL using g_module_open.
116 * Only the system and program directories are searched.
118 * @param module_name The name of the DLL.
119 * @param flags Flags to be passed to g_module_open.
120 * @return A handle to the DLL if found, NULL on failure.
122 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
125 * utf8 version of getenv, needed to get win32 filename paths
127 extern char *getenv_utf8(const char *varname);
132 * The structure to pass to ws_fstat64().
134 #define ws_statb64 struct stat
136 /* Not Windows, presumed to be UN*X-compatible */
138 #define ws_rename rename
139 #define ws_mkdir(dir,mode) mkdir(dir,mode)
140 #define ws_stat64 stat
141 #define ws_unlink unlink
142 #define ws_remove remove
143 #define ws_fopen fopen
144 #define ws_freopen freopen
147 #define ws_write write
148 #define ws_close close
150 #define ws_fstat64 fstat /* AC_SYS_LARGEFILE should make off_t 64-bit */
151 #define ws_lseek64 lseek /* AC_SYS_LARGEFILE should make off_t 64-bit */
152 #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
156 /* directory handling */
158 #define WS_DIRENT const char
159 #define ws_dir_open g_dir_open
160 #define ws_dir_read_name g_dir_read_name
161 #define ws_dir_get_name(dirent) dirent
162 #define ws_dir_rewind g_dir_rewind
163 #define ws_dir_close g_dir_close
165 /* XXX - remove include "dirent.h" */
166 /* XXX - remove include "direct.h" */
167 /* XXX - remove include "sys/stat.h" */
168 /* XXX - update docs (e.g. README.developer) */
172 #endif /* __cplusplus */
174 #endif /* __FILE_UTIL_H__ */