Update comments to reflect that the GLib version is no longer relevant
[metze/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 #include <gmodule.h>
37 #endif
38
39 #ifdef HAVE_SYS_STAT_H
40 #include <sys/stat.h>
41 #endif
42
43
44 #ifdef _WIN32
45
46 /*
47  * The structure to pass to ws_stat64() and ws_fstat64().
48  */
49 #define ws_statb64      struct _stat64
50
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.)
60  *
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.
64  */
65
66 #include <stdio.h>
67
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);
74
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);
77
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
86
87 /*
88  * These routines don't take pathnames, so they don't require
89  * pathname-converting wrappers on Windows.
90  */
91 #define ws_read    _read
92 #define ws_write   _write
93 #define ws_close   _close
94 #define ws_dup     _dup
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
98 /* DLL loading */
99
100 /** Try to remove the current directory from the DLL search path.
101  * SetDllDirectory is tried, then SetCurrentDirectory(program_dir)
102  *
103  * @return TRUE if we were able to call SetDllDirectory, FALSE otherwise.
104  */
105 gboolean ws_init_dll_search_path();
106
107 /** Load a DLL using LoadLibrary.
108  * Only the system and program directories are searched.
109  *
110  * @param library_name The name of the DLL.
111  * @return A handle to the DLL if found, NULL on failure.
112  */
113
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.
117  *
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.
121  */
122 GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
123
124 /*
125  * utf8 version of getenv, needed to get win32 filename paths
126  */
127 extern char *getenv_utf8(const char *varname);
128
129 #else   /* _WIN32 */
130
131 /*
132  * The structure to pass to ws_fstat64().
133  */
134 #define ws_statb64      struct stat
135
136 /* Not Windows, presumed to be UN*X-compatible */
137 #define ws_open                 open
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
145
146 #define ws_read    read
147 #define ws_write   write
148 #define ws_close   close
149 #define ws_dup     dup
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() */
153
154 #endif /* _WIN32 */
155
156 /* directory handling */
157 #define WS_DIR                          GDir
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
164
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) */
169
170 #ifdef __cplusplus
171 }
172 #endif /* __cplusplus */
173
174 #endif /* __FILE_UTIL_H__ */