2 Copyright (C) 2009 John Emmas
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_msvc_extensions_h__
21 #define __ardour_msvc_extensions_h__
24 #define _WIN32_WINNT 0x0500
34 #include <boost/regex.h>
36 #include <ardourext/float_cast.h>
38 // 'std::isnan()' is not available in MSVC. Assume '_isnan(double)'
39 #define isnan(val) (bool)_isnan((double)val)
41 // 'std::isinf()' is not available in MSVC. Assume '!_finite(double)'
42 #define isinf(val) !((bool)_finite((double)val))
44 // 'INFINITY' is not defined in MSVC. Assume 'HUGE_VAL'
46 #define INFINITY HUGE_VAL
49 // File access modes copied from unistd.h
55 // Miscellaneous #defines
56 #define __attribute__(x)
59 #define access _access
60 #define getcwd _getcwd
61 #define getpid _getpid
62 #define snprintf _snprintf
63 #define link ntfs_link
64 #define unlink ntfs_unlink
65 #define strcasecmp stricmp
66 #define strncasecmp strnicmp
67 #define strtok_r( _s, _sep, _lasts ) \
68 ( *(_lasts) = strtok( (_s), (_sep) ) )
71 #define PATH_MAX _MAX_PATH
73 #define DECLARE_DEFAULT_COMPARISONS(Type) \
74 extern bool operator > (const Type& lhs, const Type& rhs); \
75 extern bool operator < (const Type& lhs, const Type& rhs); \
76 extern bool operator != (const Type& lhs, const Type& rhs); \
77 extern bool operator == (const Type& lhs, const Type& rhs);
79 // Types missing from Win32 'stat.h' (hopefully Windows
80 // will either act sensibly or ignore most of them).
81 #define _S_IFBLK 0x3000
82 #define S_IRWXU _S_IRWXU
83 #define S_IXUSR _S_IXUSR
84 #define S_IWUSR _S_IWUSR
85 #define S_IRUSR _S_IRUSR
86 #define S_IXGRP _S_IXGRP
87 #define S_IWGRP _S_IWGRP
88 #define S_IRGRP _S_IRGRP
89 #define S_IXOTH _S_IXOTH
90 #define S_IWOTH _S_IWOTH
91 #define S_IROTH _S_IROTH
93 #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
94 #define _S_IXUSR _S_IEXEC
95 #define _S_IWUSR _S_IWRITE
96 #define _S_IRUSR _S_IREAD
97 #define _S_IXGRP _S_IEXEC
98 #define _S_IWGRP _S_IWRITE
99 #define _S_IRGRP _S_IREAD
100 #define _S_IXOTH _S_IEXEC
101 #define _S_IWOTH _S_IWRITE
102 #define _S_IROTH _S_IREAD
104 #define S_ISFIFO(m) _S_ISFIFO(m)
105 #define S_ISDIR(m) _S_ISDIR(m)
106 #define S_ISCHR(m) _S_ISCHR(m)
107 #define S_ISBLK(m) _S_ISBLK(m)
108 #define S_ISREG(m) _S_ISREG(m)
110 #define _S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
111 #define _S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
112 #define _S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR)
113 #define _S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK)
114 #define _S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
117 #if defined(__USE_BSD) || defined(_BSD_SOURCE)
118 /* Convenience macros for operations on timevals.
119 NOTE: `timercmp' does not work for >= or <=.
120 Note also that 'timerset', 'timerclear' and
121 'timercmp' are (perhaps strangely) already
122 defined, along with various other 'time'
123 functions in WinSock.h */
124 # define timeradd(a, b, result) \
126 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
127 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
128 if ((result)->tv_usec >= 1000000) \
130 ++(result)->tv_sec; \
131 (result)->tv_usec -= 1000000; \
134 # define timersub(a, b, result) \
136 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
137 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
138 if ((result)->tv_usec < 0) { \
139 --(result)->tv_sec; \
140 (result)->tv_usec += 1000000; \
145 #if !defined(__BIT_TYPES_DEFINED) || !defined(__BIT_TYPES_DEFINED__)
146 #define __BIT_TYPES_DEFINED__ 1
147 // Doesn't yet define all 'bit types'. Only those
148 // needed by Ardour. More can be added as needed.
149 #ifndef __int8_t_defined
150 #define __int8_t_defined
151 typedef unsigned char u_int8_t;
152 typedef unsigned short int u_int16_t;
153 typedef unsigned int u_int32_t;
154 typedef unsigned __int64 u_int64_t;
156 typedef signed char int8_t;
157 typedef unsigned char uint8_t;
158 typedef short int16_t;
159 typedef unsigned short uint16_t;
161 typedef unsigned uint32_t;
162 typedef long long int64_t;
163 typedef unsigned long long uint64_t;
166 #ifndef __register_t_defined
167 #define __register_t_defined
168 typedef int register_t;
169 #endif // __register_t
170 #endif // __BIT_TYPESD
174 #define __THROW throw()
177 // round().... Unlike Linux, Windows doesn't seem to support the
178 // concept of a system-wide (or programmable) rounding direction.
179 // Fortunately, 'round to nearest' seems to be the default action
180 // under Linux, so let's copy that until we find out otherwise.
181 #define rint(value) round(value)
182 #define round(value) floor((value) + 0.5)
184 // System V compatibility
185 typedef unsigned short ushort;
186 typedef unsigned int uint;
191 typedef unsigned short _mode_t;
194 typedef _mode_t mode_t;
195 #endif /* NO_OLDNAMES */
196 #endif /* _MODE_T_ */
199 #define fmin(a, b) min((double)a, (double)b)
200 #define fmax(a, b) max((double)a, (double)b)
202 // approximate POSIX pipe()
203 #define pipe(handles) _pipe(handles, 4096, _O_BINARY)
205 // Windows mkdir() doesn't care about access privileges
206 #define mkdir(path, mode) _mkdir(path)
208 // Redefine 'ftruncate()' to use the glib-win32 version
209 #define ftruncate(fd, len) g_win32_ftruncate((gint)fd, (guint)len)
212 // #include the main headers for Ardour MSVC
213 #if defined(BUILDING_PBD) || defined(PBD_IS_IN_WIN_STATIC_LIB)
214 #include <pbd/msvc_pbd.h>
216 #if defined(BUILDING_LIBARDOUR) || defined(LIBARDOUR_IS_IN_WIN_STATIC_LIB)
217 #include <ardour/msvc_libardour.h>
219 #if defined(BUILDING_RUBBERBAND) || defined(RUBBERBAND_IS_IN_WIN_STATIC_LIB)
220 #include <rubberband/msvc_rubberband.h>
223 #endif /* __ardour_msvc_extensions_h__ */