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 */
38 #ifdef HAVE_SYS_STAT_H
43 /* Win32: Since GLib2.6, we use UTF8 throughout the code, so file functions
44 * must tweak a given filename from UTF8 to UTF16 as we use NT Unicode (Win9x
45 * - now unsupported - used locale based encoding here).
47 #if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
50 extern int ws_stdio_open (const gchar *filename, int flags, int mode);
51 extern int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
52 extern int ws_stdio_mkdir (const gchar *filename, int mode);
53 extern int ws_stdio_stat (const gchar *filename, struct stat *buf);
54 extern int ws_stdio_unlink (const gchar *filename);
55 extern int ws_stdio_remove (const gchar *filename);
56 extern FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
57 extern FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
59 #define ws_open ws_stdio_open
60 #define ws_rename ws_stdio_rename
61 #define ws_mkdir ws_stdio_mkdir
62 #define ws_stat ws_stdio_stat
63 #define ws_unlink ws_stdio_unlink
64 #define ws_remove ws_stdio_remove
65 #define ws_fopen ws_stdio_fopen
66 #define ws_freopen ws_stdio_freopen
68 #else /* _WIN32 && GLIB_CHECK_VERSION */
70 /* "Not Windows" or GLib < 2.6: use "old school" functions */
74 #define ws_unlink _unlink
75 #define ws_mkdir(dir,mode) _mkdir(dir)
79 #define ws_unlink unlink
80 #define ws_mkdir(dir,mode) mkdir(dir,mode)
83 #define ws_rename rename
84 #define ws_remove remove
85 #define ws_fopen fopen
86 #define ws_freopen freopen
88 #endif /* _WIN32 && GLIB_CHECK_VERSION */
91 /* some common file function differences between UNIX and WIN32 */
93 /* the Win32 API prepends underscores for whatever reasons */
95 #define ws_write _write
96 #define ws_close _close
98 #define ws_lseek _lseek
101 #define ws_write write
102 #define ws_close close
104 #define ws_lseek lseek
105 #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
108 /* directory handling */
110 #define WS_DIRENT const char
111 #define ws_dir_open g_dir_open
112 #define ws_dir_read_name g_dir_read_name
113 #define ws_dir_get_name(dirent) dirent
114 #define ws_dir_rewind g_dir_rewind
115 #define ws_dir_close g_dir_close
117 /* XXX - remove include "dirent.h" */
118 /* XXX - remove include "direct.h" */
119 /* XXX - remove include "sys/stat.h" */
120 /* XXX - update docs (e.g. README.developer) */
124 #endif /* __cplusplus */
126 #endif /* __FILE_UTIL_H__ */