1 /***************************************************************************
2 
3     file        : portability.h
4     created     : Fri Jul 8 15:19:34 CET 2005
5     copyright   : (C) 2005 Bernhard Wymann
6     email       : berniw@bluewin.ch
7     version     : $Id: portability.h,v 1.2.2.3 2012/05/19 14:47:30 berniw Exp $
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  ***************************************************************************/
19 
20 #ifndef _TORCS_PORTABILITY_H_
21 #define _TORCS_PORTABILITY_H_
22 
23 #include <stdlib.h>
24 #include <cstring>
25 
26 #ifdef WIN32
27 #define HAVE_CONFIG_H
28 #endif
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 // Missing strndup, define it here (for FreeBSD).
35 // TODO: Move it into library.
36 // strndup code provided by Thierry Thomas.
37 #ifndef HAVE_STRNDUP
38 
strndup(const char * str,int len)39 static char *strndup(const char *str, int len)
40 {
41 	char *ret;
42 
43 	if ((str == NULL || len < 0)) {
44 		return (NULL);
45 	}
46 
47 	ret = (char *) malloc(len + 1);
48 	if (ret == NULL) {
49 		return (NULL);
50 	}
51 
52 	memcpy(ret, str, len);
53 	ret[len] = '\0';
54 	return (ret);
55 }
56 
57 #endif
58 
59 
60 #ifdef WIN32
61 #define snprintf _snprintf
62 #if _MSC_VER < 1500
63 #define vsnprintf _vsnprintf
64 #endif
65 #endif
66 
67 #ifdef WIN32
68 #include <math.h>
69 
round(float x)70 static float round(float x)
71 {
72 	return floor(x+0.5f);
73 }
74 #endif
75 
76 #endif // _TORCS_PORTABILITY_H_
77 
78