1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* file_util.h
* File utility definitions
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __FILE_UTIL_H__
#define __FILE_UTIL_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <glib.h>
#ifdef _WIN32
#include <io.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
/* Win32: Since GLib2.6, we use UTF8 throughout the code, so file functions
* must tweak a given filename from UTF8 to UTF16 as we use NT Unicode (Win9x
* - now unsupported - used locale based encoding here).
*/
#if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
#include <stdio.h>
extern int eth_stdio_open (const gchar *filename, int flags, int mode);
extern int eth_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
extern int eth_stdio_mkdir (const gchar *filename, int mode);
extern int eth_stdio_stat (const gchar *filename, struct stat *buf);
extern int eth_stdio_unlink (const gchar *filename);
extern int eth_stdio_remove (const gchar *filename);
extern FILE * eth_stdio_fopen (const gchar *filename, const gchar *mode);
extern FILE * eth_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
#define eth_open eth_stdio_open
#define eth_rename eth_stdio_rename
#define eth_mkdir eth_stdio_mkdir
#define eth_stat eth_stdio_stat
#define eth_unlink eth_stdio_unlink
#define eth_remove eth_stdio_remove
#define eth_fopen eth_stdio_fopen
#define eth_freopen eth_stdio_freopen
#else /* _WIN32 && GLIB_CHECK_VERSION */
/* GLib 2.4 or below, using "old school" functions */
#ifdef _WIN32
#define eth_open _open
#define eth_stat _stat
#define eth_unlink _unlink
#define eth_mkdir(dir,mode) _mkdir(dir)
#else
#define eth_open open
#define eth_stat stat
#define eth_unlink unlink
#define eth_mkdir(dir,mode) mkdir(dir,mode)
#endif /* _WIN32 */
#define eth_rename rename
#define eth_remove remove
#define eth_fopen fopen
#define eth_freopen freopen
#endif /* _WIN32 && GLIB_CHECK_VERSION */
/* some common file function differences between UNIX and WIN32 */
#ifdef _WIN32
/* the Win32 API prepends underscores for whatever reasons */
#define eth_read _read
#define eth_write _write
#define eth_close _close
#define eth_dup _dup
#define eth_lseek _lseek
#else
#define eth_read read
#define eth_write write
#define eth_close close
#define eth_dup dup
#define eth_lseek lseek
#define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
#endif /* _WIN32 */
/* directory handling */
#define ETH_DIR GDir
#define ETH_DIRENT const char
#define eth_dir_open g_dir_open
#define eth_dir_read_name g_dir_read_name
#define eth_dir_get_name(dirent) dirent
#define eth_dir_rewind g_dir_rewind
#define eth_dir_close g_dir_close
/* XXX - remove include "dirent.h" */
/* XXX - remove include "direct.h" */
/* XXX - remove include "sys/stat.h" */
/* XXX - update docs (e.g. README.developer) */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __FILE_UTIL_H__ */
|