1 /////////////////////////////////////////////////////////////////////////
2 // $Id: osdep.h,v 1.28 2008/02/05 22:57:40 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
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
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.
44 #endif /* __cplusplus */
46 //////////////////////////////////////////////////////////////////////
47 // Hacks for win32, but exclude MINGW32 because it doesn't need them.
48 //////////////////////////////////////////////////////////////////////
51 // Definitions that are needed for all WIN32 compilers.
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
61 #define FMT_TICK "%011llu"
62 #define FMT_ADDRX64 "%016llx"
65 #define FMT_TICK "%011I64u"
66 #define FMT_ADDRX64 "%016I64x"
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
83 #define lseek _lseeki64
84 #define fstat _fstati64
88 #else /* __MINGW32__ defined */
89 // Definitions for cygwin compiled with -mno-cygwin
91 #define FMT_TICK "%011I64u"
92 #define FMT_ADDRX64 "%016I64x"
95 #define lseek _lseeki64
96 #endif /* __MINGW32__ defined */
98 #else /* not WIN32 definitions */
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
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
, ...);
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
);
144 // great, just use the usual function
145 #elif BX_HAVE_STRTOUQ
146 // they have strtouq and not strtoull
147 #define strtoull strtouq
149 #define strtoull bx_strtoull
150 extern Bit64u
bx_strtoull (const char *nptr
, char **endptr
, int baseignore
);
154 #define strdup bx_strdup
155 extern char *bx_strdup(const char *str
);
159 #define strrev bx_strrev
160 extern char *bx_strrev(char *str
);
163 #if !BX_HAVE_SOCKLEN_T
164 // needed on MacOS X 10.1
165 typedef int socklen_t
;
169 #define mkstemp bx_mkstemp
170 extern int bx_mkstemp(char *tpl
);
173 //////////////////////////////////////////////////////////////////////
174 // Missing library functions, implemented for MacOS only
175 //////////////////////////////////////////////////////////////////////
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
;
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);
201 #undef BX_HAVE_MSLEEP
202 #define BX_HAVE_MSLEEP 1
204 #define msleep(msec) _sleep(msec)
206 #define msleep(msec) Sleep(msec)
212 #endif /* __cplusplus */
214 #endif /* ifdef BX_OSDEP_H */