Merge pull request #50 from pali/master Simplify UNICODE build
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
diff --git a/.appveyor.yml b/.appveyor.yml
index c269f59..fb6c5da 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -34,22 +34,52 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\MinGW\bin'
+ BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\MinGW\bin'
BUILD_SHARED_LIBS: OFF
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\MinGW\bin'
+ BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin'
BUILD_SHARED_LIBS: ON
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin'
+ BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin'
+ BUILD_SHARED_LIBS: OFF
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin'
BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin'
+ BUILD_SHARED_LIBS: ON
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin'
BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
@@ -58,24 +88,54 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin'
+ BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin'
BUILD_SHARED_LIBS: ON
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin'
+ BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin'
+ BUILD_SHARED_LIBS: OFF
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin'
BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
+ BUILD_SHARED_LIBS: ON
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
BUILD_SHARED_LIBS: OFF
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
+ BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
@@ -84,15 +144,37 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "MinGW Makefiles"
cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
+ BUILD_SHARED_LIBS: ON
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
+ BUILD_SHARED_LIBS: OFF
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+ GENERATOR: "MinGW Makefiles"
+ cc_path: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin'
BUILD_SHARED_LIBS: OFF
+ CFLAGS: '-DUNICODE -D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+ GENERATOR: "Visual Studio 15 2017"
+ BUILD_SHARED_LIBS: ON
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017"
BUILD_SHARED_LIBS: ON
+ CFLAGS: '/DUNICODE /D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
+ GENERATOR: "Visual Studio 15 2017"
+ BUILD_SHARED_LIBS: OFF
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017"
BUILD_SHARED_LIBS: OFF
+ CFLAGS: '/DUNICODE /D_UNICODE'
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015"
@@ -100,15 +182,35 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015"
+ BUILD_SHARED_LIBS: ON
+ CFLAGS: '/DUNICODE /D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "Visual Studio 14 2015"
BUILD_SHARED_LIBS: OFF
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "Visual Studio 14 2015"
+ BUILD_SHARED_LIBS: OFF
+ CFLAGS: '/DUNICODE /D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "Visual Studio 12 2013"
+ BUILD_SHARED_LIBS: ON
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 12 2013"
BUILD_SHARED_LIBS: ON
+ CFLAGS: '/DUNICODE /D_UNICODE'
+
+ - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
+ GENERATOR: "Visual Studio 12 2013"
+ BUILD_SHARED_LIBS: OFF
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 12 2013"
BUILD_SHARED_LIBS: OFF
+ CFLAGS: '/DUNICODE /D_UNICODE'
platform:
- Win32
diff --git a/dlfcn.c b/dlfcn.c
index 8d3c793..8687c51 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -46,19 +46,6 @@
#endif
#include "dlfcn.h"
-#if ((defined(_WIN32) || defined(WIN32)) && (defined(_MSC_VER)) )
-#define snprintf sprintf_s
-#endif
-
-#ifdef UNICODE
-#include <wchar.h>
-#define CHAR wchar_t
-#define UNICODE_L(s) L##s
-#else
-#define CHAR char
-#define UNICODE_L(s) s
-#endif
-
/* Note:
* MSDN says these functions are not thread-safe. We make no efforts to have
* any kind of thread safety.
@@ -142,49 +129,45 @@ static void local_rem( HMODULE hModule )
* MSDN says the buffer cannot be larger than 64K bytes, so we set it to
* the limit.
*/
-static CHAR error_buffer[65535];
-static CHAR *current_error;
+static char error_buffer[65535];
+static char *current_error;
static char dlerror_buffer[65536];
-static int copy_string( CHAR *dest, int dest_size, const CHAR *src )
-{
- int i = 0;
-
- /* gcc should optimize this out */
- if( !src || !dest )
- return 0;
-
- for( i = 0 ; i < dest_size-1 ; i++ )
- {
- if( !src[i] )
- break;
- else
- dest[i] = src[i];
- }
- dest[i] = '\0';
-
- return i;
-}
-
-static void save_err_str( const CHAR *str )
+static void save_err_str( const char *str )
{
DWORD dwMessageId;
- DWORD pos;
+ DWORD ret;
+ size_t pos, len;
dwMessageId = GetLastError( );
if( dwMessageId == 0 )
return;
+ len = strlen( str );
+ if( len > sizeof( error_buffer ) - 5 )
+ len = sizeof( error_buffer ) - 5;
+
/* Format error message to:
* "<argument to function that failed>": <Windows localized error message>
*/
- pos = copy_string( error_buffer, sizeof(error_buffer), UNICODE_L("\"") );
- pos += copy_string( error_buffer+pos, sizeof(error_buffer)-pos, str );
- pos += copy_string( error_buffer+pos, sizeof(error_buffer)-pos, UNICODE_L("\": ") );
- pos += FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwMessageId,
+ pos = 0;
+ error_buffer[pos++] = '"';
+ memcpy( error_buffer+pos, str, len );
+ pos += len;
+ error_buffer[pos++] = '"';
+ error_buffer[pos++] = ':';
+ error_buffer[pos++] = ' ';
+
+ ret = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwMessageId,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
- error_buffer+pos, sizeof(error_buffer)-pos, NULL );
+ error_buffer+pos, (DWORD) (sizeof(error_buffer)-pos), NULL );
+ pos += ret;
+
+ /* When FormatMessageA() fails it returns zero and does not touch buffer
+ * so add trailing null byte */
+ if( ret == 0 )
+ error_buffer[pos] = '\0';
if( pos > 1 )
{
@@ -198,19 +181,13 @@ static void save_err_str( const CHAR *str )
static void save_err_ptr_str( const void *ptr )
{
- CHAR ptr_buf[19]; /* 0x<pointer> up to 64 bits. */
-
-#ifdef UNICODE
-
-# if ((defined(_WIN32) || defined(WIN32)) && (defined(_MSC_VER)) )
- swprintf_s( ptr_buf, 19, UNICODE_L("0x%p"), ptr );
-# else
- swprintf(ptr_buf, 19, UNICODE_L("0x%p"), ptr);
-# endif
+ char ptr_buf[19]; /* 0x<pointer> up to 64 bits. */
-#else
- snprintf( ptr_buf, 19, "0x%p", ptr );
+#ifdef _MSC_VER
+/* Supress warning C4996: 'sprintf': This function or variable may be unsafe */
+#pragma warning( suppress: 4996 )
#endif
+ sprintf( ptr_buf, "0x%p", ptr );
save_err_str( ptr_buf );
}
@@ -246,7 +223,7 @@ void *dlopen( const char *file, int mode )
{
HANDLE hCurrentProc;
DWORD dwProcModsBefore, dwProcModsAfter;
- CHAR lpFileName[MAX_PATH];
+ char lpFileName[MAX_PATH];
size_t i;
/* MSDN says backslashes *must* be used instead of forward slashes. */
@@ -271,7 +248,7 @@ void *dlopen( const char *file, int mode )
* to UNIX's search paths (start with system folders instead of current
* folder).
*/
- hModule = LoadLibraryEx(lpFileName, NULL,
+ hModule = LoadLibraryExA(lpFileName, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH );
if( EnumProcessModules( hCurrentProc, NULL, 0, &dwProcModsAfter ) == 0 )
@@ -331,11 +308,6 @@ void *dlsym( void *handle, const char *name )
HMODULE hModule;
HANDLE hCurrentProc;
-#ifdef UNICODE
- wchar_t namew[MAX_PATH];
- wmemset(namew, 0, MAX_PATH);
-#endif
-
current_error = NULL;
symbol = NULL;
hCaller = NULL;
@@ -426,23 +398,7 @@ void *dlsym( void *handle, const char *name )
end:
if( symbol == NULL )
{
-#ifdef UNICODE
- size_t converted_chars;
-
- size_t str_len = strlen(name) + 1;
-
-#if ((defined(_WIN32) || defined(WIN32)) && (defined(_MSC_VER)) )
- errno_t err = mbstowcs_s(&converted_chars, namew, str_len, name, str_len);
- if (err != 0)
- return NULL;
-#else
- mbstowcs(namew, name, str_len);
-#endif
-
- save_err_str( namew );
-#else
save_err_str( name );
-#endif
}
// warning C4054: 'type cast' : from function pointer 'FARPROC' to data pointer 'void *'
@@ -462,26 +418,7 @@ char *dlerror( void )
return NULL;
}
-#ifdef UNICODE
- errno_t err = 0;
- size_t converted_chars = 0;
- size_t str_len = wcslen(current_error) + 1;
- memset(error_pointer, 0, 65535);
-
-# if ((defined(_WIN32) || defined(WIN32)) && (defined(_MSC_VER)) )
- err = wcstombs_s(&converted_chars,
- error_pointer, str_len * sizeof(char),
- current_error, str_len * sizeof(wchar_t));
-
- if (err != 0)
- return NULL;
-# else
- wcstombs(error_pointer, current_error, str_len);
-# endif
-
-#else
memcpy(error_pointer, current_error, strlen(current_error) + 1);
-#endif
/* POSIX says that invoking dlerror( ) a second time, immediately following
* a prior invocation, shall result in NULL being returned.