From 6475603985c511c29fd027079286bb99d60a6a4a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 29 Nov 2007 15:32:49 +0100 Subject: [PATCH] libwine: Work around the Mac OS dynamic loader support for PE files. --- libs/wine/loader.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libs/wine/loader.c b/libs/wine/loader.c index 2f782484441..13eb84af39f 100644 --- a/libs/wine/loader.c +++ b/libs/wine/loader.c @@ -668,6 +668,25 @@ void *wine_dlopen( const char *filename, int flag, char *error, size_t errorsize #ifdef HAVE_DLOPEN void *ret; const char *s; + +#ifdef __APPLE__ + /* the Mac OS loader pretends to be able to load PE files, so avoid them here */ + unsigned char magic[2]; + int fd = open( filename, O_RDONLY ); + if (fd != -1) + { + if (pread( fd, magic, 2, 0 ) == 2 && magic[0] == 'M' && magic[1] == 'Z') + { + static const char msg[] = "MZ format"; + size_t len = min( errorsize, sizeof(msg) ); + memcpy( error, msg, len ); + error[len - 1] = 0; + close( fd ); + return NULL; + } + close( fd ); + } +#endif dlerror(); dlerror(); #ifdef __sun if (strchr( filename, ':' ))