TORCS  1.3.9
The Open Racing Car Simulator
portability.h
Go to the documentation of this file.
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$
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 
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 // Only redefine for MSVC versions older than 1900 (Visual Studio 2015)
62 // VS 2022 has _MSC_VER = 193x, so snprintf/vsnprintf exist there.
63 #if _MSC_VER < 1900
64 #define snprintf _snprintf
65 #endif
66 
67 #if _MSC_VER < 1500
68 #define vsnprintf _vsnprintf
69 #endif
70 
71 #endif
72 
73 #ifdef WIN32
74 #include <math.h>
75 #if _MSC_VER < 1800 // VS2013 (_MSC_VER=1800) and later have round()
76 static float round(float x)
77 {
78  return floor(x+0.5f);
79 }
80 #endif
81 #endif
82 
83 #endif // _TORCS_PORTABILITY_H_
84 
static char * strndup(const char *str, int len)
Definition: portability.h:39