From Edgar Gladkich:
[obnox/wireshark/wip.git] / wsutil / file_util.h
1 /* file_util.h
2  * File utility definitions
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef __FILE_UTIL_H__
26 #define __FILE_UTIL_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <glib.h>
33
34 #ifdef _WIN32
35 #include <io.h>
36 #endif
37
38 #ifdef HAVE_SYS_STAT_H
39 #include <sys/stat.h>
40 #endif
41
42
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).
46  */
47 #if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
48 #include <stdio.h>
49
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);
58
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
67
68 #else   /* _WIN32 && GLIB_CHECK_VERSION */
69
70 /* "Not Windows" or GLib < 2.6: use "old school" functions */
71 #ifdef _WIN32
72 #define ws_open         _open
73 #define ws_stat         _stat
74 #define ws_unlink       _unlink
75 #define ws_mkdir(dir,mode)      _mkdir(dir)
76 #else
77 #define ws_open         open
78 #define ws_stat         stat
79 #define ws_unlink       unlink
80 #define ws_mkdir(dir,mode)      mkdir(dir,mode)
81 #endif /* _WIN32 */
82
83 #define ws_rename       rename
84 #define ws_remove       remove
85 #define ws_fopen        fopen
86 #define ws_freopen      freopen
87
88 #endif  /* _WIN32 && GLIB_CHECK_VERSION */
89
90
91 /* some common file function differences between UNIX and WIN32 */
92 #ifdef _WIN32
93 /* the Win32 API prepends underscores for whatever reasons */
94 #define ws_read  _read
95 #define ws_write _write
96 #define ws_close _close
97 #define ws_dup   _dup
98 #define ws_lseek _lseek
99 #else
100 #define ws_read  read
101 #define ws_write write
102 #define ws_close close
103 #define ws_dup   dup
104 #define ws_lseek lseek
105 #define O_BINARY        0               /* Win32 needs the O_BINARY flag for open() */
106 #endif /* _WIN32 */
107
108 /* directory handling */
109 #define WS_DIR                          GDir
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
116
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) */
121
122 #ifdef __cplusplus
123 }
124 #endif /* __cplusplus */
125
126 #endif /* __FILE_UTIL_H__ */