2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2004-02-08 13:22:29 +03:00
|
|
|
// $Id: osdep.h,v 1.20 2004-02-08 10:22:29 cbothamy Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 06:02:05 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2001-04-10 05:51:16 +04:00
|
|
|
//
|
|
|
|
// osdep.h
|
2001-04-10 06:02:05 +04:00
|
|
|
//
|
|
|
|
// requires Bit32u/Bit64u from config.h, size_t from stdio.h
|
2001-04-10 05:51:16 +04:00
|
|
|
//
|
2001-04-10 06:02:05 +04:00
|
|
|
// Operating system dependent includes and defines for Bochs. These
|
|
|
|
// declarations can be included by C or C++., but they require definition of
|
|
|
|
// size_t beforehand. This makes it difficult to place them into either
|
|
|
|
// config.h or bochs.h. If in config.h, size_t is not always available yet.
|
|
|
|
// If in bochs.h, they can't be included by C programs so they lose.
|
2001-04-10 05:51:16 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef BX_OSDEP_H
|
|
|
|
#define BX_OSDEP_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2001-06-22 17:35:48 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Hacks for win32, but exclude MINGW32 because it doesn't need them.
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef WIN32
|
2001-10-05 10:07:00 +04:00
|
|
|
|
2002-03-06 21:04:58 +03:00
|
|
|
// Definitions that are needed for all WIN32 compilers.
|
|
|
|
# define ssize_t long
|
|
|
|
|
2001-06-22 17:35:48 +04:00
|
|
|
#ifndef __MINGW32__
|
2003-06-07 23:16:55 +04:00
|
|
|
#define FMT_LL "%I64"
|
|
|
|
|
2002-03-06 21:04:58 +03:00
|
|
|
// Definitions that are needed for WIN32 compilers EXCEPT FOR
|
|
|
|
// cygwin compiling with -mno-cygwin. e.g. VC++.
|
2001-10-05 10:07:00 +04:00
|
|
|
|
2001-06-22 17:35:48 +04:00
|
|
|
// always return regular file.
|
2001-10-01 21:01:00 +04:00
|
|
|
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
|
|
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
2001-06-22 17:35:48 +04:00
|
|
|
|
|
|
|
// win32 has snprintf though with different name.
|
|
|
|
#define snprintf _snprintf
|
2004-02-08 13:22:29 +03:00
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#undef BX_HAVE_SNPRINTF
|
|
|
|
#undef BX_HAVE_VSNPRINTF
|
|
|
|
#define BX_HAVE_SNPRINTF 1
|
|
|
|
#define BX_HAVE_VSNPRINTF 1
|
2003-06-07 23:16:55 +04:00
|
|
|
#else /* ifnndef __MINGW32__ */
|
|
|
|
#define FMT_LL "%ll"
|
2001-06-22 17:35:48 +04:00
|
|
|
#endif /* ifnndef __MINGW32__ */
|
2003-06-07 23:16:55 +04:00
|
|
|
#else /* WIN32 */
|
|
|
|
#define FMT_LL "%ll"
|
2001-06-22 17:35:48 +04:00
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2003-05-07 00:28:13 +04:00
|
|
|
// Missing defines for open
|
|
|
|
#ifndef S_IRUSR
|
|
|
|
#define S_IRUSR 0400
|
|
|
|
#define S_IWUSR 0200
|
2003-05-07 01:53:36 +04:00
|
|
|
#endif
|
|
|
|
#ifndef S_IRGRP
|
2003-05-07 00:28:13 +04:00
|
|
|
#define S_IRGRP 0040
|
|
|
|
#define S_IWGRP 0020
|
2003-05-07 01:53:36 +04:00
|
|
|
#endif
|
|
|
|
#ifndef S_IROTH
|
2003-05-07 00:28:13 +04:00
|
|
|
#define S_IROTH 0004
|
|
|
|
#define S_IWOTH 0002
|
2003-05-07 01:53:36 +04:00
|
|
|
#endif
|
2003-05-07 00:28:13 +04:00
|
|
|
|
2001-04-10 06:02:05 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Missing library functions.
|
|
|
|
// These should work on any platform that needs them.
|
|
|
|
//
|
|
|
|
// A missing library function is renamed to a bx_* function, so that when
|
|
|
|
// debugging and linking there's no confusion over which version is used.
|
|
|
|
// Because of renaming, the bx_* replacement functions can be tested on
|
|
|
|
// machines which have the real library function without duplicate symbols.
|
|
|
|
//
|
|
|
|
// If you're considering implementing a missing library function, note
|
|
|
|
// that it might be cleaner to conditionally disable the function call!
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2001-04-10 05:51:16 +04:00
|
|
|
|
2001-04-10 06:02:05 +04:00
|
|
|
#if !BX_HAVE_SNPRINTF
|
2004-02-08 13:22:29 +03:00
|
|
|
#define snprintf bx_snprintf
|
2001-04-10 05:51:16 +04:00
|
|
|
extern int bx_snprintf (char *s, size_t maxlen, const char *format, ...);
|
|
|
|
#endif
|
|
|
|
|
2004-02-08 13:22:29 +03:00
|
|
|
#if !BX_HAVE_VSNPRINTF
|
|
|
|
#define vsnprintf bx_vsnprintf
|
|
|
|
extern int bx_vsnprintf (char *s, size_t maxlen, const char *format, va_list arg);
|
|
|
|
#endif
|
|
|
|
|
2001-05-17 11:00:42 +04:00
|
|
|
#if BX_HAVE_STRTOULL
|
|
|
|
// great, just use the usual function
|
|
|
|
#elif BX_HAVE_STRTOUQ
|
|
|
|
// they have strtouq and not strtoull
|
|
|
|
#define strtoull strtouq
|
|
|
|
#else
|
|
|
|
#define strtoull bx_strtoull
|
2001-04-10 06:02:05 +04:00
|
|
|
extern Bit64u bx_strtoull (const char *nptr, char **endptr, int baseignore);
|
|
|
|
#endif
|
2001-04-10 05:51:16 +04:00
|
|
|
|
2001-04-10 06:02:05 +04:00
|
|
|
#if !BX_HAVE_STRDUP
|
|
|
|
#define strdup bx_strdup
|
|
|
|
extern char *bx_strdup(const char *str);
|
2001-04-10 05:51:16 +04:00
|
|
|
#endif
|
|
|
|
|
2003-01-11 01:32:46 +03:00
|
|
|
#if !BX_HAVE_STRREV
|
|
|
|
#define strrev bx_strrev
|
|
|
|
extern char *bx_strrev(char *str);
|
|
|
|
#endif
|
|
|
|
|
2002-03-08 07:45:00 +03:00
|
|
|
#if !BX_HAVE_SOCKLEN_T
|
|
|
|
// needed on MacOS X 10.1
|
|
|
|
typedef int socklen_t;
|
|
|
|
#endif
|
|
|
|
|
2003-05-07 00:28:13 +04:00
|
|
|
#if !BX_HAVE_MKSTEMP
|
|
|
|
#define mkstemp bx_mkstemp
|
|
|
|
extern int bx_mkstemp(char *tpl);
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 06:02:05 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Missing library functions, implemented for MacOS only
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if BX_WITH_MACOS
|
|
|
|
// fd_read and fd_write are called by floppy.cc to access the Mac
|
|
|
|
// floppy drive directly, since the MacOS doesn't have "special"
|
|
|
|
// pathnames which map directly to IO devices
|
2001-04-10 05:51:16 +04:00
|
|
|
|
2001-04-10 06:02:05 +04:00
|
|
|
int fd_read(char *buffer, Bit32u offset, Bit32u bytes);
|
|
|
|
int fd_write(char *buffer, Bit32u offset, Bit32u bytes);
|
|
|
|
int fd_stat(struct stat *buf);
|
2002-12-12 18:29:45 +03:00
|
|
|
FILE * fdopen(int fd, const char *type);
|
|
|
|
|
|
|
|
typedef long ssize_t ;
|
2001-04-10 06:02:05 +04:00
|
|
|
#endif
|
2001-04-10 05:51:16 +04:00
|
|
|
|
2002-09-23 06:20:52 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// New functions to replace library functions
|
|
|
|
// with OS-independent versions
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if BX_HAVE_REALTIME_USEC
|
|
|
|
// 64-bit time in useconds.
|
|
|
|
extern Bit64u bx_get_realtime64_usec (void);
|
|
|
|
#endif
|
|
|
|
|
2003-08-20 10:26:27 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
#undef BX_HAVE_MSLEEP
|
|
|
|
#define BX_HAVE_MSLEEP 1
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
#define msleep(msec) _sleep(msec)
|
|
|
|
#else
|
|
|
|
#define msleep(msec) Sleep(msec)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:51:16 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif /* ifdef BX_OSDEP_H */
|