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
44 /* Win32: Since GLib2.6, we use UTF8 throughout the code, so file functions
45 * must tweak a given filename from UTF8 to UTF16 as we use NT Unicode (Win9x
46 * - now unsupported - used locale based encoding here).
48 #if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
51 extern int ws_stdio_open (const gchar *filename, int flags, int mode);
52 extern int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
53 extern int ws_stdio_mkdir (const gchar *filename, int mode);
54 extern int ws_stdio_stat (const gchar *filename, struct stat *buf);
55 extern int ws_stdio_unlink (const gchar *filename);
56 extern int ws_stdio_remove (const gchar *filename);
57 extern FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
58 extern FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
60 #define ws_open ws_stdio_open
61 #define ws_rename ws_stdio_rename
62 #define ws_mkdir ws_stdio_mkdir
63 #define ws_stat ws_stdio_stat
64 #define ws_unlink ws_stdio_unlink
65 #define ws_remove ws_stdio_remove
66 #define ws_fopen ws_stdio_fopen
67 #define ws_freopen ws_stdio_freopen
69 #else /* _WIN32 && GLIB_CHECK_VERSION */
71 /* "Not Windows" or GLib < 2.6: use "old school" functions */
75 #define ws_unlink _unlink
76 #define ws_mkdir(dir,mode) _mkdir(dir)
80 #define ws_unlink unlink
81 #define ws_mkdir(dir,mode) mkdir(dir,mode)
84 #define ws_rename rename
85 #define ws_remove remove
86 #define ws_fopen fopen
87 #define ws_freopen freopen
89 #endif /* _WIN32 && GLIB_CHECK_VERSION */
92 /* some common file function differences between UNIX and WIN32 */
94 /* the Win32 API prepends underscores for whatever reasons */
96 #define ws_write _write
97 #define ws_close _close
99 #define ws_lseek _lseek
103 /** Try to remove the current directory from the DLL search path.
104 * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
106 * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
108 gboolean ws_init_dll_search_path();
110 /** Load a DLL using LoadLibrary.
111 * Only the system and program directories are searched.
113 * @param library_name The name of the DLL.
114 * @return A handle to the DLL if found, NULL on failure.
117 void *ws_load_library(gchar *library_name);
118 /** Load a DLL using g_module_open.
119 * Only the system and program directories are searched.
121 * @param module_name The name of the DLL.
122 * @param flags Flags to be passed to g_module_open.
123 * @return A handle to the DLL if found, NULL on failure.
125 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
128 #define ws_write write
129 #define ws_close close
131 #define ws_lseek lseek
132 #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
135 /* directory handling */
137 #define WS_DIRENT const char
138 #define ws_dir_open g_dir_open
139 #define ws_dir_read_name g_dir_read_name
140 #define ws_dir_get_name(dirent) dirent
141 #define ws_dir_rewind g_dir_rewind
142 #define ws_dir_close g_dir_close
144 /* XXX - remove include "dirent.h" */
145 /* XXX - remove include "direct.h" */
146 /* XXX - remove include "sys/stat.h" */
147 /* XXX - update docs (e.g. README.developer) */
151 #endif /* __cplusplus */
153 #endif /* __FILE_UTIL_H__ */