'libs/ardour' - Main body of changes required for building with MSVC
[ardour.git] / libs / pbd / pbd / msvc_pbd.h
1 /*
2     Copyright (C) 2009 John Emmas
3
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.
8
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.
13
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.
17
18 */
19 #ifndef _msvc_pbd_h_
20 #define _msvc_pbd_h_
21
22 #ifdef  PBD_IS_IN_WIN_STATIC_LIB  // #define if your project uses libpbd (under Windows) as a static library
23 #define PBD_IS_IN_WINDLL 0
24 #endif
25
26 #ifndef COMPILER_MSVC
27 #include <sys/time.h>
28 #else
29 #include <ardourext/misc.h>
30 #include <ardourext/sys/time.h>
31 #endif
32
33 #if !defined(PBD_IS_IN_WINDLL)
34         #if defined(COMPILER_MSVC) || defined(COMPILER_MINGW)
35         // If you need '__declspec' compatibility, add extra compilers to the above as necessary
36                 #define PBD_IS_IN_WINDLL 1
37         #else
38                 #define PBD_IS_IN_WINDLL 0
39         #endif
40 #endif
41
42 #if PBD_IS_IN_WINDLL && !defined(PBD_API)
43         #if defined(BUILDING_PBD)
44                 #define PBD_API __declspec(dllexport)
45                 #define PBD_APICALLTYPE __stdcall
46         #elif defined(COMPILER_MSVC) || defined(COMPILER_MINGW) // Probably needs Cygwin too, at some point
47                 #define PBD_API __declspec(dllimport)
48                 #define PBD_APICALLTYPE __stdcall
49         #else
50                 #error "Attempting to define __declspec with an incompatible compiler !"
51         #endif
52 #elif !defined(PBD_API)
53         // Other compilers / platforms could be accommodated here
54         #define PBD_API
55         #define PBD_APICALLTYPE
56         #define GETOPT_API
57         #define GETOPT_APICALLTYPE
58 #endif
59
60 #ifndef GETOPT_API
61         #if defined(BUILDING_GETOPT)
62                 #define GETOPT_API __declspec(dllexport)
63                 #define GETOPT_APICALLTYPE __cdecl
64         #elif defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW__) || defined(_MINGW32__)
65                 #define GETOPT_API __declspec(dllimport)
66                 #define GETOPT_APICALLTYPE __cdecl
67         #else
68                 #error "Attempting to define __declspec with an incompatible compiler !"
69         #endif
70 #endif  // GETOPT_API
71
72 #ifndef _MAX_PATH
73 #define _MAX_PATH  260
74 #endif
75 #ifndef  PATH_MAX
76 #define  PATH_MAX _MAX_PATH
77 #endif
78
79 #ifdef __cplusplus
80 extern "C" {
81 #endif  /* __cplusplus */
82
83 // This function is (hopefully) temporary and is placed here
84 // because 'g_usleep()' doesn't seem to work very well for glib-win32
85 void    pbd_g_usleep (unsigned long microseconds);
86
87 #ifdef __cplusplus
88 }               /* extern "C" */
89 #endif  /* __cplusplus */
90
91 #ifndef POLLIN
92 #define POLLIN                          1
93 #define POLLPRI                         2
94 #define POLLOUT                         4
95 #define POLLERR                         8
96 #define POLLHUP                         16
97 #define POLLNVAL                        32
98 #define NPOLLFILE                       64
99
100 #define POLLRDNORM                      POLLIN
101 #define POLLRDBAND                      POLLIN
102 #define POLLWRNORM                      POLLOUT
103 #define POLLWRBAND                      POLLOUT
104 #endif
105
106 #ifdef PLATFORM_WINDOWS
107
108 #ifndef PBDEXTN_API
109         #if defined(BUILDING_PBDEXTN)
110                 #define PBDEXTN_API __declspec(dllexport)
111                 #define PBDEXTN_APICALLTYPE __cdecl
112         #elif defined(COMPILER_MSVC) || defined(COMPILER_MINGW) // Probably needs Cygwin too, at some point
113                 #define PBDEXTN_API __declspec(dllimport)
114                 #define PBDEXTN_APICALLTYPE __cdecl
115         #else
116                 #error "Attempting to define __declspec with an incompatible compiler !"
117         #endif
118 #endif  // PBDEXTN_API
119
120 #ifndef CYGIMPORT_API
121                 #define CYGIMPORT_API __declspec(dllimport)
122                 #define CYGIMPORT_APICALLTYPE __cdecl
123 #endif  // CYGIMPORT_API
124
125 #ifndef __THROW
126 #define __THROW throw()
127 #endif
128
129 #ifndef RTLD_DEFAULT
130 #define RTLD_DEFAULT       ((void *) 0)
131 #define RTLD_NEXT          ((void *) -1L)
132 #define RTLD_LAZY          0x00001
133 #define RTLD_NOW           0x00002
134 #define RTLD_BINDING_MASK  0x00003
135 #define RTLD_NOLOAD        0x00004
136 #define RTLD_GLOBAL        0x00004
137 #define RTLD_DEEPBIND      0x00008
138 #endif
139
140 #ifndef OPEN_MAX
141 #define OPEN_MAX                        32
142 #endif
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif  /* __cplusplus */
147
148 PBDEXTN_API int         PBDEXTN_APICALLTYPE cyginit (unsigned int result);
149 PBD_API     int         PBD_APICALLTYPE     dlclose (void *handle) __THROW;
150 PBD_API     void*       PBD_APICALLTYPE     dlopen  (const char *file_name, int mode) __THROW;
151 PBD_API     void*       PBD_APICALLTYPE     dlsym   (void *handle, const char *symbol_name) __THROW;
152 PBD_API     char*       PBD_APICALLTYPE     dlerror () __THROW;
153
154 #ifdef __cplusplus
155 }               /* extern "C" */
156 #endif  /* __cplusplus */
157
158 #ifndef __CYGWIN__
159 #include <rpc.h>
160 #include <io.h>
161 #include <sys/types.h>
162
163 typedef int (FAR PBDEXTN_APICALLTYPE *CYGINIT_API)(unsigned int);
164
165 #ifndef FILENAME_MAX
166 #define FILENAME_MAX (260)
167 #endif
168
169 #ifndef _SSIZE_T_
170 #define _SSIZE_T_
171 typedef long _ssize_t;
172
173 #ifndef _NO_OLDNAMES
174 typedef _ssize_t ssize_t;
175 #endif
176 #endif /* ! _SSIZE_T_ */
177
178 struct dirent
179 {
180         long                    d_ino;                            // Always zero
181         unsigned short  d_reclen;                         // Always zero
182         unsigned short  d_namlen;                         // Length of name in d_name
183         char                    d_name[FILENAME_MAX]; // File name
184 };
185
186 // This is an internal data structure. Do not use it
187 // except as an argument to one of the functions below.
188 typedef struct
189 {
190         // Disk transfer area for this dir
191         struct _finddata_t      dd_dta;
192
193         // 'dirent' struct to return from dir (NOTE: this
194         // is not thread safe).
195         struct dirent           dd_dir;
196
197         // '_findnext()' handle
198         long                            dd_handle;
199
200         // Current status of search:
201         //  0 = not started yet (next entry to read is first entry)
202         // -1 = off the end
203         //  Otherwise - positive (0 based) index of next entry
204         int                                     dd_stat;
205
206         // Full path for dir with search pattern (struct will be extended)
207         char                            dd_name[1];
208 } DIR;
209
210 struct pollfd
211 {
212         int fd;
213         short events;
214         short revents;
215 };
216
217 typedef unsigned int nfds_t;
218
219 PBD_API int                             PBD_APICALLTYPE gettimeofday(struct timeval *__restrict tv, __timezone_ptr_t tz);
220 PBD_API ssize_t                 PBD_APICALLTYPE pread(int handle, void *buf, size_t nbytes, off_t offset);
221 PBD_API ssize_t                 PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t nbytes, off_t offset);
222 PBD_API int                             PBD_APICALLTYPE poll(struct pollfd *fds, nfds_t nfds, int timeout);
223 PBD_API double                  PBD_APICALLTYPE round(double x);
224
225 namespace PBD {
226
227 #ifdef __cplusplus
228 extern "C" {
229 #endif  /* __cplusplus */
230
231 PBD_API bool                    PBD_APICALLTYPE TestForMinimumSpecOS(char *revision="currently ignored");
232 PBD_API char*                   PBD_APICALLTYPE realpath    (const char *original_path, char resolved_path[_MAX_PATH+1]);
233 PBD_API int                             PBD_APICALLTYPE mkstemp     (char *template_name);
234 PBD_API int                             PBD_APICALLTYPE ntfs_link   (const char *existing_filepath, const char *link_filepath);
235 PBD_API int                             PBD_APICALLTYPE ntfs_unlink (const char *link_filepath);
236
237 // These are used to replicate 'dirent.h' functionality
238 PBD_API DIR*                    PBD_APICALLTYPE opendir  (const char *szPath);
239 PBD_API struct dirent*  PBD_APICALLTYPE readdir  (DIR *pDir);
240 PBD_API int                             PBD_APICALLTYPE closedir (DIR *pDir);
241
242 #ifdef __cplusplus
243 }               /* extern "C" */
244 #endif  /* __cplusplus */
245
246 }  // namespace PBD
247
248 #endif  // !__CYGWIN__
249 #endif  // PLATFORM_WINDOWS
250 #endif  // _msvc_pbd_h_