97ac72ff27419a775580682531e08055fc667f06
[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 #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 #ifdef __cplusplus
86 }               /* extern "C" */
87 #endif  /* __cplusplus */
88
89 #ifdef PLATFORM_WINDOWS
90
91 #ifndef PBDEXTN_API
92         #if defined(BUILDING_PBDEXTN)
93                 #define PBDEXTN_API __declspec(dllexport)
94                 #define PBDEXTN_APICALLTYPE __cdecl
95         #elif defined(COMPILER_MSVC) || defined(COMPILER_MINGW) // Probably needs Cygwin too, at some point
96                 #define PBDEXTN_API __declspec(dllimport)
97                 #define PBDEXTN_APICALLTYPE __cdecl
98         #else
99                 #error "Attempting to define __declspec with an incompatible compiler !"
100         #endif
101 #endif  // PBDEXTN_API
102
103 #ifndef CYGIMPORT_API
104                 #define CYGIMPORT_API __declspec(dllimport)
105                 #define CYGIMPORT_APICALLTYPE __cdecl
106 #endif  // CYGIMPORT_API
107
108 #ifndef __THROW
109 #define __THROW throw()
110 #endif
111
112 #ifndef RTLD_DEFAULT
113 #define RTLD_DEFAULT       ((void *) 0)
114 #define RTLD_NEXT          ((void *) -1L)
115 #define RTLD_LAZY          0x00001
116 #define RTLD_NOW           0x00002
117 #define RTLD_BINDING_MASK  0x00003
118 #define RTLD_NOLOAD        0x00004
119 #define RTLD_GLOBAL        0x00004
120 #define RTLD_DEEPBIND      0x00008
121 #endif
122
123 #ifndef OPEN_MAX
124 #define OPEN_MAX                        32
125 #endif
126
127 #ifdef __cplusplus
128 extern "C" {
129 #endif  /* __cplusplus */
130
131 PBDEXTN_API        int          PBDEXTN_APICALLTYPE cyginit (unsigned int result);
132 LIBPBD_API     int              PBD_APICALLTYPE     dlclose (void *handle) __THROW;
133 LIBPBD_API     void*    PBD_APICALLTYPE     dlopen  (const char *file_name, int mode) __THROW;
134 LIBPBD_API     void*    PBD_APICALLTYPE     dlsym   (void *handle, const char *symbol_name) __THROW;
135 LIBPBD_API     char*    PBD_APICALLTYPE     dlerror () __THROW;
136
137 #ifdef __cplusplus
138 }               /* extern "C" */
139 #endif  /* __cplusplus */
140
141 #ifndef __CYGWIN__
142 /* For whatever reason, Ardour's 'libevoral' refuses to build as a DLL if we include both 'rpc.h' */
143 /* and 'WinSock2.h'. It doesn't seem to matter which order we #include them. Given that we can't  */
144 /* edit 'rpc.h' or 'WinSock2.h', just make sure we don't #include them when building libevoral.   */
145 #ifndef BUILDING_EVORAL
146 #include <rpc.h>
147 typedef int (FAR PBDEXTN_APICALLTYPE *CYGINIT_API)(unsigned int);
148 #endif
149 #include <io.h>
150 #include <sys/types.h>
151
152 #ifndef FILENAME_MAX
153 #define FILENAME_MAX (260)
154 #endif
155
156 #ifndef _SSIZE_T_
157 #define _SSIZE_T_
158 typedef long _ssize_t;
159
160 #ifndef _NO_OLDNAMES
161 typedef _ssize_t ssize_t;
162 #endif
163 #endif /* ! _SSIZE_T_ */
164
165 struct dirent
166 {
167         long                    d_ino;                            // Always zero
168         unsigned short  d_reclen;                         // Always zero
169         unsigned short  d_namlen;                         // Length of name in d_name
170         char                    d_name[FILENAME_MAX]; // File name
171 };
172
173 // This is an internal data structure. Do not use it
174 // except as an argument to one of the functions below.
175 typedef struct
176 {
177         // Disk transfer area for this dir
178         struct _finddata_t      dd_dta;
179
180         // 'dirent' struct to return from dir (NOTE: this
181         // is not thread safe).
182         struct dirent           dd_dir;
183
184         // '_findnext()' handle
185         long                            dd_handle;
186
187         // Current status of search:
188         //  0 = not started yet (next entry to read is first entry)
189         // -1 = off the end
190         //  Otherwise - positive (0 based) index of next entry
191         int                                     dd_stat;
192
193         // Full path for dir with search pattern (struct will be extended)
194         char                            dd_name[1];
195 } DIR;
196
197 typedef unsigned int nfds_t;
198
199 #ifdef __cplusplus
200 extern "C" {
201 #endif  /* __cplusplus */
202
203 LIBPBD_API int                          __cdecl         gettimeofday(struct timeval *__restrict tv, __timezone_ptr_t tz);
204 LIBPBD_API ssize_t                      PBD_APICALLTYPE pread(int handle, void *buf, size_t nbytes, off_t offset);
205 LIBPBD_API ssize_t                      PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t nbytes, off_t offset);
206
207 #if defined(_MSC_VER) && (_MSC_VER < 1800)
208 LIBPBD_API double                       PBD_APICALLTYPE expm1(double x);
209 LIBPBD_API double                       PBD_APICALLTYPE log1p(double x);
210 LIBPBD_API double                       PBD_APICALLTYPE round(double x);
211 LIBPBD_API float                        PBD_APICALLTYPE roundf(float x);
212 #endif
213
214 #if defined(_MSC_VER) && (_MSC_VER < 1900)
215 LIBPBD_API double                       PBD_APICALLTYPE log2 (double x);
216 LIBPBD_API double                       PBD_APICALLTYPE trunc(double x);
217 #endif
218
219 namespace PBD {
220
221 LIBPBD_API bool                         PBD_APICALLTYPE TestForMinimumSpecOS(char *revision="currently ignored");
222 LIBPBD_API char*                        PBD_APICALLTYPE realpath    (const char *original_path, char resolved_path[_MAX_PATH+1]);
223 LIBPBD_API int                          PBD_APICALLTYPE mkstemp     (char *template_name);
224 LIBPBD_API int                          PBD_APICALLTYPE ntfs_link   (const char *existing_filepath, const char *link_filepath);
225 LIBPBD_API int                          PBD_APICALLTYPE ntfs_unlink (const char *link_filepath);
226
227 // These are used to replicate 'dirent.h' functionality
228 LIBPBD_API DIR*                         PBD_APICALLTYPE opendir  (const char *szPath);
229 LIBPBD_API struct dirent*       PBD_APICALLTYPE readdir  (DIR *pDir);
230 LIBPBD_API int                          PBD_APICALLTYPE closedir (DIR *pDir);
231
232 }  // namespace PBD
233
234 #ifdef __cplusplus
235 }               /* extern "C" */
236 #endif  /* __cplusplus */
237
238 #endif  // !__CYGWIN__
239 #endif  // PLATFORM_WINDOWS
240 #endif  // _msvc_pbd_h_