# endif
# undef GetProcAddress
# define GetProcAddress GetProcAddressA
+
+static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName)
+ {
+ WCHAR *fnamw;
+ size_t len_0=strlen(lpLibFileName)+1,i;
+
+#ifdef _MSC_VER
+ fnamw = (WCHAR *)_alloca (len_0*sizeof(WCHAR));
+#else
+ fnamw = (WCHAR *)alloca (len_0*sizeof(WCHAR));
+#endif
+ if (fnamw == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return NULL;
+ }
+
+#if defined(_WIN32_WCE) && _WIN32_WCE>=101
+ if (!MultiByteToWideChar(CP_ACP,0,lpLibFileName,len_0,fnamw,len_0))
+#endif
+ for (i=0;i<len_0;i++) fnamw[i]=(WCHAR)lpLibFileName[i];
+
+ return LoadLibraryW(fnamw);
+ }
#endif
/* Part of the hack in "win32_load" ... */
static char *win32_merger(DSO *dso, const char *filespec1,
const char *filespec2);
static int win32_pathbyaddr(void *addr,char *path,int sz);
+static void *win32_globallookup(const char *name);
static const char *openssl_strnchr(const char *string, int c, size_t len);
win32_merger,
NULL, /* init */
NULL, /* finish */
- win32_pathbyaddr
+ win32_pathbyaddr,
+ win32_globallookup
};
DSO_METHOD *DSO_METHOD_win32(void)
struct file_st *result = NULL;
enum { IN_NODE, IN_DEVICE, IN_FILE } position;
const char *start = filename;
+ char last;
if (!filename)
{
memset(result, 0, sizeof(struct file_st));
position = IN_DEVICE;
- if(filename[0] == '\\' && filename[1] == '\\'
- || filename[0] == '/' && filename[1] == '/')
+ if((filename[0] == '\\' && filename[1] == '\\')
+ || (filename[0] == '/' && filename[1] == '/'))
{
position = IN_NODE;
filename += 2;
do
{
- switch(filename[0])
+ last = filename[0];
+ switch(last)
{
case ':':
if(position != IN_DEVICE)
start = ++filename;
result->dir = start;
}
+ else if(position == IN_DEVICE)
+ {
+ position = IN_FILE;
+ filename++;
+ result->dir = start;
+ result->dirlen = filename - start;
+ start = filename;
+ }
else
{
filename++;
result->dirlen += filename - start;
+ start = filename;
}
break;
case '\0':
{
if (assume_last_is_dir)
{
- result->devicelen += filename - start;
+ if (position == IN_DEVICE)
+ {
+ result->dir = start;
+ result->dirlen = 0;
+ }
+ result->dirlen +=
+ filename - start;
}
else
{
result->file = start;
- result->filelen = filename - start;
+ result->filelen =
+ filename - start;
}
}
}
break;
}
}
- while(*filename);
+ while(last);
if(!result->nodelen) result->node = NULL;
if(!result->devicelen) result->device = NULL;
result[offset] = '\\'; offset++;
start = end + 1;
}
+#if 0 /* Not needed, since the directory converter above already appeneded
+ a backslash */
if(file_split->predir && (file_split->dir || file_split->file))
{
result[offset] = '\\'; offset++;
}
+#endif
start = file_split->dir;
while(file_split->dirlen > (start - file_split->dir))
{
result[offset] = '\\'; offset++;
start = end + 1;
}
+#if 0 /* Not needed, since the directory converter above already appeneded
+ a backslash */
if(file_split->dir && file_split->file)
{
result[offset] = '\\'; offset++;
}
+#endif
strncpy(&result[offset], file_split->file,
file_split->filelen); offset += file_split->filelen;
result[offset] = '\0';
}
else
{
- filespec1_split = win32_splitter(dso, filespec1, 1);
+ filespec1_split = win32_splitter(dso, filespec1, 0);
if (!filespec1_split)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
- filespec2_split = win32_splitter(dso, filespec2, 0);
- if (!filespec1_split)
+ filespec2_split = win32_splitter(dso, filespec2, 1);
+ if (!filespec2_split)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
dll = LoadLibrary(TEXT(DLLNAME));
if (dll == NULL)
{
- DSOerr(DSO_F_PATHBYADDR,DSO_R_UNSUPPORTED);
+ DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
return -1;
}
GetProcAddress(dll,"CreateToolhelp32Snapshot");
if (create_snap == NULL)
{
- DSOerr(DSO_F_PATHBYADDR,DSO_R_UNSUPPORTED);
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
return -1;
}
/* We take the rest for granted... */
if( hModuleSnap == INVALID_HANDLE_VALUE )
{
FreeLibrary(dll);
- DSOerr(DSO_F_PATHBYADDR,DSO_R_UNSUPPORTED);
+ DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_UNSUPPORTED);
return -1;
}
{
(*close_snap)(hModuleSnap);
FreeLibrary(dll);
- DSOerr(DSO_F_PATHBYADDR,DSO_R_FAILURE);
+ DSOerr(DSO_F_WIN32_PATHBYADDR,DSO_R_FAILURE);
return -1;
}
FreeLibrary(dll);
return 0;
}
+
+static void *win32_globallookup(const char *name)
+ {
+ HMODULE dll;
+ HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
+ MODULEENTRY32 me32;
+ CREATETOOLHELP32SNAPSHOT create_snap;
+ CLOSETOOLHELP32SNAPSHOT close_snap;
+ MODULE32 module_first, module_next;
+ FARPROC ret=NULL;
+
+ dll = LoadLibrary(TEXT(DLLNAME));
+ if (dll == NULL)
+ {
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+
+ create_snap = (CREATETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll,"CreateToolhelp32Snapshot");
+ if (create_snap == NULL)
+ {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+ /* We take the rest for granted... */
+#ifdef _WIN32_WCE
+ close_snap = (CLOSETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll,"CloseToolhelp32Snapshot");
+#else
+ close_snap = (CLOSETOOLHELP32SNAPSHOT)CloseHandle;
+#endif
+ module_first = (MODULE32)GetProcAddress(dll,"Module32First");
+ module_next = (MODULE32)GetProcAddress(dll,"Module32Next");
+
+ hModuleSnap = (*create_snap)(TH32CS_SNAPMODULE,0);
+ if( hModuleSnap == INVALID_HANDLE_VALUE )
+ {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP,DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+
+ me32.dwSize = sizeof(me32);
+
+ if (!(*module_first)(hModuleSnap,&me32))
+ {
+ (*close_snap)(hModuleSnap);
+ FreeLibrary(dll);
+ return NULL;
+ }
+
+ do {
+ if ((ret = GetProcAddress(me32.hModule,name)))
+ {
+ (*close_snap)(hModuleSnap);
+ FreeLibrary(dll);
+ return ret;
+ }
+ } while((*module_next)(hModuleSnap,&me32));
+
+ (*close_snap)(hModuleSnap);
+ FreeLibrary(dll);
+ return NULL;
+ }
#endif /* DSO_WIN32 */