diff options
-rw-r--r-- | lib.c | 36 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | match.c | 1 | ||||
-rw-r--r-- | sysif.c | 38 | ||||
-rw-r--r-- | sysif.h | 1 |
5 files changed, 39 insertions, 38 deletions
@@ -130,7 +130,6 @@ val list_f, less_f, greater_f; val prog_string; -static val env_list; static val recycled_conses; const seq_kind_t seq_kind_tab[MAXTYPE+1] = { @@ -11867,39 +11866,6 @@ val in_range_star(val range, val num) } } -val env(void) -{ - if (env_list) { - return env_list; - } else { - list_collect_decl (out, ptail); -#if HAVE_ENVIRON - extern char **environ; - char **iter = environ; - - for (; *iter != 0; iter++) - ptail = list_collect(ptail, string_utf8(*iter)); - - return env_list = out; -#elif HAVE_GETENVIRONMENTSTRINGS - wchar_t *env = GetEnvironmentStringsW(); - wchar_t *iter = env; - - if (iter == 0) - oom(); - - for (; *iter; iter += wcslen(iter) + 1) - ptail = list_collect(ptail, string(iter)); - - FreeEnvironmentStringsW(env); - - return env_list = out; -#else - uw_throwf(error_s, lit("environment strings not available"), nao); -#endif - } -} - static void obj_init(void) { val self = lit("internal init"); @@ -11915,7 +11881,7 @@ static void obj_init(void) &null_list, &equal_f, &eq_f, &eql_f, &car_f, &cdr_f, &null_f, &list_f, &identity_f, &identity_star_f, &less_f, &greater_f, - &prog_string, &env_list, + &prog_string, convert(val *, 0)); nil_string = lit("nil"); @@ -1195,7 +1195,6 @@ val set_from(val range, val from); val set_to(val range, val to); val in_range(val range, val num); val in_range_star(val range, val num); -val env(void); void out_str_char(wchar_t ch, val out, int *semi_flag, int regex); val obj_print_impl(val obj, val out, val pretty, struct strm_ctx *); val obj_print(val obj, val stream, val pretty); @@ -47,6 +47,7 @@ #include "hash.h" #include "eval.h" #include "cadr.h" +#include "sysif.h" #include "match.h" int opt_print_bindings = 0; @@ -148,6 +148,8 @@ static val at_exit_list; static val dirent_st; +static val env_list; + static val errno_wrap(val newval) { val self = lit("errno"); @@ -287,6 +289,39 @@ static val getppid_wrap(void) #endif +val env(void) +{ + if (env_list) { + return env_list; + } else { + list_collect_decl (out, ptail); +#if HAVE_ENVIRON + extern char **environ; + char **iter = environ; + + for (; *iter != 0; iter++) + ptail = list_collect(ptail, string_utf8(*iter)); + + return env_list = out; +#elif HAVE_GETENVIRONMENTSTRINGS + wchar_t *env = GetEnvironmentStringsW(); + wchar_t *iter = env; + + if (iter == 0) + oom(); + + for (; *iter; iter += wcslen(iter) + 1) + ptail = list_collect(ptail, string(iter)); + + FreeEnvironmentStringsW(env); + + return env_list = out; +#else + uw_throwf(error_s, lit("environment strings not available"), nao); +#endif + } +} + static val env_hash(void) { val env_strings = env(); @@ -2354,8 +2389,7 @@ static val dirstat(val dirent, val dir_path, val stat_opt) void sysif_init(void) { - prot1(&at_exit_list); - prot1(&dirent_st); + protect(&at_exit_list, dirent_st, &env_list, convert(val *, 0)); atexit(at_exit_handler); @@ -36,6 +36,7 @@ extern val atime_nsec_s, mtime_nsec_s, ctime_nsec_s; extern val path_s; val errno_to_file_error(int err); +val env(void); val getenv_wrap(val name); val errno_to_str(int err); val at_exit_call(val func); |