Fixed compilation error
[bochs-mirror.git] / osdep.h
blobbe4a1a77ddb33cea1e81b88c4b70b5ddec9a3c06
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: osdep.h,v 1.28 2008/02/05 22:57:40 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 // osdep.h
30 // requires Bit32u/Bit64u from config.h, size_t from stdio.h
32 // Operating system dependent includes and defines for Bochs. These
33 // declarations can be included by C or C++., but they require definition of
34 // size_t beforehand. This makes it difficult to place them into either
35 // config.h or bochs.h. If in config.h, size_t is not always available yet.
36 // If in bochs.h, they can't be included by C programs so they lose.
39 #ifndef BX_OSDEP_H
40 #define BX_OSDEP_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif /* __cplusplus */
46 //////////////////////////////////////////////////////////////////////
47 // Hacks for win32, but exclude MINGW32 because it doesn't need them.
48 //////////////////////////////////////////////////////////////////////
49 #ifdef WIN32
51 // Definitions that are needed for all WIN32 compilers.
52 # define ssize_t long
54 #ifndef __MINGW32__
56 // Definitions that are needed for WIN32 compilers EXCEPT FOR
57 // cygwin compiling with -mno-cygwin. e.g. VC++.
59 #if !defined(_MSC_VER) // gcc without -mno-cygwin
60 #define FMT_LL "%ll"
61 #define FMT_TICK "%011llu"
62 #define FMT_ADDRX64 "%016llx"
63 #else
64 #define FMT_LL "%I64"
65 #define FMT_TICK "%011I64u"
66 #define FMT_ADDRX64 "%016I64x"
67 #endif
69 // always return regular file.
70 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
71 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
73 // win32 has snprintf though with different name.
74 #define snprintf _snprintf
75 #define vsnprintf _vsnprintf
76 #undef BX_HAVE_SNPRINTF
77 #undef BX_HAVE_VSNPRINTF
78 #define BX_HAVE_SNPRINTF 1
79 #define BX_HAVE_VSNPRINTF 1
81 #if defined(_MSC_VER)
82 #define off_t __int64
83 #define lseek _lseeki64
84 #define fstat _fstati64
85 #define stat _stati64
86 #endif
88 #else /* __MINGW32__ defined */
89 // Definitions for cygwin compiled with -mno-cygwin
90 #define FMT_LL "%I64"
91 #define FMT_TICK "%011I64u"
92 #define FMT_ADDRX64 "%016I64x"
94 #define off_t __int64
95 #define lseek _lseeki64
96 #endif /* __MINGW32__ defined */
98 #else /* not WIN32 definitions */
99 #define FMT_LL "%ll"
100 #define FMT_TICK "%011llu"
101 #define FMT_ADDRX64 "%016llx"
102 #endif /* not WIN32 definitions */
104 #define FMT_ADDRX32 "%08x"
106 // Missing defines for open
107 #ifndef S_IRUSR
108 #define S_IRUSR 0400
109 #define S_IWUSR 0200
110 #endif
111 #ifndef S_IRGRP
112 #define S_IRGRP 0040
113 #define S_IWGRP 0020
114 #endif
115 #ifndef S_IROTH
116 #define S_IROTH 0004
117 #define S_IWOTH 0002
118 #endif
120 //////////////////////////////////////////////////////////////////////
121 // Missing library functions.
122 // These should work on any platform that needs them.
124 // A missing library function is renamed to a bx_* function, so that when
125 // debugging and linking there's no confusion over which version is used.
126 // Because of renaming, the bx_* replacement functions can be tested on
127 // machines which have the real library function without duplicate symbols.
129 // If you're considering implementing a missing library function, note
130 // that it might be cleaner to conditionally disable the function call!
131 //////////////////////////////////////////////////////////////////////
133 #if !BX_HAVE_SNPRINTF
134 #define snprintf bx_snprintf
135 extern int bx_snprintf (char *s, size_t maxlen, const char *format, ...);
136 #endif
138 #if !BX_HAVE_VSNPRINTF
139 #define vsnprintf bx_vsnprintf
140 extern int bx_vsnprintf (char *s, size_t maxlen, const char *format, va_list arg);
141 #endif
143 #if BX_HAVE_STRTOULL
144 // great, just use the usual function
145 #elif BX_HAVE_STRTOUQ
146 // they have strtouq and not strtoull
147 #define strtoull strtouq
148 #else
149 #define strtoull bx_strtoull
150 extern Bit64u bx_strtoull (const char *nptr, char **endptr, int baseignore);
151 #endif
153 #if !BX_HAVE_STRDUP
154 #define strdup bx_strdup
155 extern char *bx_strdup(const char *str);
156 #endif
158 #if !BX_HAVE_STRREV
159 #define strrev bx_strrev
160 extern char *bx_strrev(char *str);
161 #endif
163 #if !BX_HAVE_SOCKLEN_T
164 // needed on MacOS X 10.1
165 typedef int socklen_t;
166 #endif
168 #if !BX_HAVE_MKSTEMP
169 #define mkstemp bx_mkstemp
170 extern int bx_mkstemp(char *tpl);
171 #endif
173 //////////////////////////////////////////////////////////////////////
174 // Missing library functions, implemented for MacOS only
175 //////////////////////////////////////////////////////////////////////
177 #if BX_WITH_MACOS
178 // fd_read and fd_write are called by floppy.cc to access the Mac
179 // floppy drive directly, since the MacOS doesn't have "special"
180 // pathnames which map directly to IO devices
182 int fd_read(char *buffer, Bit32u offset, Bit32u bytes);
183 int fd_write(char *buffer, Bit32u offset, Bit32u bytes);
184 int fd_stat(struct stat *buf);
185 FILE * fdopen(int fd, const char *type);
187 typedef long ssize_t ;
188 #endif
190 //////////////////////////////////////////////////////////////////////
191 // New functions to replace library functions
192 // with OS-independent versions
193 //////////////////////////////////////////////////////////////////////
195 #if BX_HAVE_REALTIME_USEC
196 // 64-bit time in useconds.
197 extern Bit64u bx_get_realtime64_usec (void);
198 #endif
200 #ifdef WIN32
201 #undef BX_HAVE_MSLEEP
202 #define BX_HAVE_MSLEEP 1
203 #ifndef __MINGW32__
204 #define msleep(msec) _sleep(msec)
205 #else
206 #define msleep(msec) Sleep(msec)
207 #endif
208 #endif
210 #ifdef __cplusplus
212 #endif /* __cplusplus */
214 #endif /* ifdef BX_OSDEP_H */