Add test which check that dlopen() can open same files as open() This ensures that dlopen() expects filenames encoded in same codepage as WinAPI's open() function.
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
diff --git a/test.c b/test.c
index aa0e0f1..c4aa81d 100644
--- a/test.c
+++ b/test.c
@@ -27,6 +27,10 @@
#include <stdio.h>
#include <string.h>
#include <windows.h>
+#include <wchar.h>
+#include <io.h>
+#include <fcntl.h>
+#include <direct.h>
#include "dlfcn.h"
/* If these dlclose's fails, we don't care as the handles are going to be
@@ -81,11 +85,14 @@ int main()
size_t (*fwrite_local) ( const void *, size_t, size_t, FILE * );
size_t (*fputs_default) ( const char *, FILE * );
int (*nonexistentfunction)( void );
+ int fd;
int ret;
HMODULE library3;
char toolongfile[32767];
DWORD code;
char nonlibraryfile[MAX_PATH];
+ char bytename[sizeof("testdll2.dll")+4];
+ WCHAR widename[sizeof("testdll2.dll")+1];
DWORD length;
HANDLE tempfile;
DWORD dummy;
@@ -210,6 +217,32 @@ int main()
else
printf( "SUCCESS\tCould not open file with too long file name via WINAPI: %lu\n", (unsigned long)code );
+ fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
+ if( fd < 0 )
+ {
+ if( _chdir( "Debug" ) == 0 )
+ {
+ fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
+ if( fd < 0 )
+ _chdir( ".." );
+ }
+ }
+ if( fd < 0 )
+ {
+ if( _chdir( "Release" ) == 0 )
+ {
+ fd = _open( "testdll2.dll", _O_RDONLY | _O_BINARY );
+ if( fd < 0 )
+ _chdir( ".." );
+ }
+ }
+ if( fd < 0 )
+ {
+ printf( "ERROR\tCould not open library2 file: %s\n", strerror( errno ) );
+ RETURN_ERROR;
+ }
+ _close( fd );
+
library2 = dlopen( "testdll2.dll", RTLD_GLOBAL );
if( !library2 )
{
@@ -220,6 +253,66 @@ int main()
else
printf( "SUCCESS\tOpened library2 globally: %p\n", library2 );
+ widename[0] = 0xE1; /* wide non-ASCII character mappable to most ANSI codepages */
+ wcscpy( widename+1, L"testdll2.dll" );
+ if( !CopyFileW( L"testdll2.dll", widename, FALSE ))
+ {
+ printf( "ERROR\tCould not copy file testdll2.dll: %lu\n", (unsigned long)GetLastError( ) );
+ RETURN_ERROR;
+ }
+ else
+ printf( "SUCCESS\tCopied testdll2.dll to wide name %ls\n", widename );
+
+ ret = WideCharToMultiByte( CP_ACP, 0, widename, -1, bytename, sizeof( bytename ), NULL, NULL );
+ /* if we cannot convert widename to current codepage (used by _open() function), skip this test */
+ if( ret > 0 )
+ {
+ bytename[ret] = 0;
+
+ fd = _wopen( widename, _O_RDONLY | _O_BINARY );
+ if( fd < 0 )
+ {
+ printf( "ERROR\tCould not open copied wide library2 file %ls: %s\n", widename, strerror( errno ) );
+ DeleteFileW( widename );
+ RETURN_ERROR;
+ }
+ _close( fd );
+
+ fd = _open( bytename, _O_RDONLY | _O_BINARY );
+ if( fd < 0 )
+ {
+ printf( "ERROR\tCould not open copied wide library2 file %s: %s\n", bytename, strerror( errno ) );
+ DeleteFileW( widename );
+ RETURN_ERROR;
+ }
+ _close( fd );
+
+ dlclose( library2 );
+ library2 = dlopen( bytename, RTLD_GLOBAL );
+ if( !library2 )
+ {
+ error = dlerror( );
+ printf( "ERROR\tCould not open copied wide library2 file %s globally: %s\n", bytename, error ? error : "" );
+ DeleteFileW( widename );
+ RETURN_ERROR;
+ }
+ else
+ printf( "SUCCESS\tOpened copied wide library2 file %s globally: %p\n", bytename, library2 );
+
+ dlclose( library2 );
+ DeleteFileW( widename );
+
+ library2 = dlopen( "testdll2.dll", RTLD_GLOBAL );
+ if( !library2 )
+ {
+ error = dlerror( );
+ printf( "ERROR\tCould not open library2 globally: %s\n", error ? error : "" );
+ RETURN_ERROR;
+ }
+ else
+ printf( "SUCCESS\tOpened library2 globally: %p\n", library2 );
+ }
+
library = dlopen( "testdll.dll", RTLD_GLOBAL );
if( !library )
{