check full file path

This commit is contained in:
Vítor Santos Costa 2015-11-09 11:26:22 +00:00
parent ca81e5d8ea
commit a8b51a1ada

View File

@ -126,8 +126,10 @@ Yap_FindExecutable(void)
void * void *
Yap_LoadForeignFile(char *file, int flags) Yap_LoadForeignFile(char *file, int flags)
{ {
CACHE_REGS
int dlflag; int dlflag;
void *out; void *out;
if (flags & EAGER_LOADING) if (flags & EAGER_LOADING)
dlflag = RTLD_NOW; dlflag = RTLD_NOW;
@ -139,11 +141,15 @@ Yap_LoadForeignFile(char *file, int flags)
else else
dlflag |= RTLD_LOCAL; dlflag |= RTLD_LOCAL;
#endif #endif
if (!Yap_TrueFileName(file, LOCAL_FileNameBuf, true)){
out = (void *)dlopen(file,dlflag); /* use LD_LIBRARY_PATH */
if (!out) { strncpy(LOCAL_FileNameBuf,file, YAP_FILENAME_MAX-1);
CACHE_REGS strncat(LOCAL_FileNameBuf,".", YAP_FILENAME_MAX-1);
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "dlopen error for %s: %s\n", file, dlerror()); 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; return out;
} }
@ -183,7 +189,7 @@ LoadForeign(StringList ofiles, StringList libs,
CACHE_REGS CACHE_REGS
while (libs) { 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 */ /* use LD_LIBRARY_PATH */
strncpy(LOCAL_FileNameBuf, (char *)AtomName(libs->name), YAP_FILENAME_MAX); 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) if((handle=dlopen(LOCAL_FileNameBuf,RTLD_LAZY|RTLD_GLOBAL)) == 0)
#endif #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());*/ /* strcpy(LOCAL_ErrorSay,dlerror());*/
return LOAD_FAILLED; return LOAD_FAILLED;
} }