From a8b51a1adad50720ecb1195f6659f19b73bdea7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 9 Nov 2015 11:26:22 +0000 Subject: [PATCH] check full file path --- C/load_dl.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/C/load_dl.c b/C/load_dl.c index 7f5c1d711..0386fecd7 100755 --- a/C/load_dl.c +++ b/C/load_dl.c @@ -126,8 +126,10 @@ Yap_FindExecutable(void) void * Yap_LoadForeignFile(char *file, int flags) { + CACHE_REGS int dlflag; void *out; + if (flags & EAGER_LOADING) dlflag = RTLD_NOW; @@ -139,11 +141,15 @@ Yap_LoadForeignFile(char *file, int flags) else dlflag |= RTLD_LOCAL; #endif - - out = (void *)dlopen(file,dlflag); - if (!out) { - CACHE_REGS - Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "dlopen error for %s: %s\n", file, dlerror()); + if (!Yap_TrueFileName(file, LOCAL_FileNameBuf, true)){ + /* use LD_LIBRARY_PATH */ + strncpy(LOCAL_FileNameBuf,file, YAP_FILENAME_MAX-1); + strncat(LOCAL_FileNameBuf,".", YAP_FILENAME_MAX-1); + strncat(LOCAL_FileNameBuf, "SO_EXT", YAP_FILENAME_MAX-1); + } + out = (void *)dlopen(LOCAL_FileNameBuf, flags); + if (out == NULL) { + Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "dlopen failed for %s: %s\n", file, dlerror()); } return out; } @@ -183,7 +189,7 @@ LoadForeign(StringList ofiles, StringList libs, CACHE_REGS while (libs) { - if (!Yap_TrueFileName((char *)AtomName(libs->name), LOCAL_FileNameBuf, TRUE)) { + if (!Yap_TrueFileName((char *)AtomName(libs->name), LOCAL_FileNameBuf, true)) { /* use LD_LIBRARY_PATH */ strncpy(LOCAL_FileNameBuf, (char *)AtomName(libs->name), YAP_FILENAME_MAX); } @@ -217,7 +223,7 @@ LoadForeign(StringList ofiles, StringList libs, if((handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == 0) #endif { - fprintf(stderr,"dlopen of %s failed with error %s\n", LOCAL_FileNameBuf, dlerror()); + fprintf(stderr,"dlopen of image %s failed: %s\n", LOCAL_FileNameBuf, dlerror()); /* strcpy(LOCAL_ErrorSay,dlerror());*/ return LOAD_FAILLED; }