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