diff --git a/s7.c b/s7.c index 22ebd73..82df0a2 100644 --- a/s7.c +++ b/s7.c @@ -25450,7 +25450,7 @@ static void leave_lock_scope(lock_scope_t *st) #else #define TRACK(Sc) #endif - + static block_t *search_load_path(s7_scheme *sc, const char *name) { s7_int len; @@ -25458,7 +25458,7 @@ static block_t *search_load_path(s7_scheme *sc, const char *name) lst = s7_load_path(sc); len = s7_list_length(sc, lst); - + if (len > 0) { block_t *b; @@ -25473,13 +25473,11 @@ static block_t *search_load_path(s7_scheme *sc, const char *name) new_dir = string_value(s7_list_ref(sc, lst, i)); if (new_dir) { - FILE *fp; filename[0] = '\0'; catstrs(filename, 1024, new_dir, "/", name, NULL); - fp = fopen(filename, "r"); - if (fp) + if (access(filename, F_OK) == 0) { - block_info(b) = (void *)fp; + return(b); } } @@ -25503,9 +25501,9 @@ s7_pointer s7_load_with_environment(s7_scheme *sc, const char *filename, s7_poin block_t *b; b = search_load_path(sc, filename); if (b) - { - new_filename = copy_string((const char *)block_data(b)); /* (require libc.scm) for example needs the directory for cload in some cases */ - fp = (FILE *)block_info(b); + { + + fp = fopen(block_data(b), "r"); liberate(sc, b); } } @@ -25632,16 +25630,20 @@ defaults to the rootlet. To load into the current environment instead, pass (cu init = s7_let_ref(sc, (is_null(sc->envir)) ? sc->rootlet : sc->envir, make_symbol(sc, "init_func")); if (is_symbol(init)) { - void *library; + void *library = NULL; char *pwd_name; block_t *pname = NULL; if (fname[0] != '/') { - pname = full_filename(sc, fname); /* this is necessary, at least in Linux -- we can't blithely dlopen whatever is passed to us */ - pwd_name = (char *)block_data(pname); + block_t *searched = search_load_path(sc, fname); + if (searched) { + pname = full_filename(sc, block_data(searched)); /* this is necessary, at least in Linux -- we can't blithely dlopen whatever is passed to us */ + pwd_name = (char *)block_data(pname); + library = dlopen((pname) ? pwd_name : fname, RTLD_NOW); + liberate(sc, searched); + } } - library = dlopen((pname) ? pwd_name : fname, RTLD_NOW); if (library) { const char *init_name; @@ -25700,9 +25702,10 @@ defaults to the rootlet. To load into the current environment instead, pass (cu { block_t *b; b = search_load_path(sc, fname); - if (!b) - return(file_error(sc, "load", "can't open", fname)); - fp = (FILE *)block_info(b); + if (b) + fp = fopen(block_data(b), "r"); + if (!fp) + return(file_error(sc, "load", "can't open", fname)); liberate(sc, b); } @@ -90390,7 +90393,7 @@ s7_scheme *s7_init(void) s7_set_setter(sc, sc->features_symbol, s7_make_function(sc, "#", g_features_set, 2, 0, false, "*features* setter")); /* -------- *load-path* -------- */ - sc->load_path_symbol = s7_define_variable_with_documentation(sc, "*load-path*", sc->nil, + sc->load_path_symbol = s7_define_variable_with_documentation(sc, "*load-path*", s7_list(sc, 1, s7_make_string(sc, ".")), "*load-path* is a list of directories (strings) that the load function searches if it is passed an incomplete file name"); s7_set_setter(sc, sc->load_path_symbol, s7_make_function(sc, "#", g_load_path_set, 2, 0, false, "*load-path* setter"));