@@ -42,23 +42,45 @@ const char *get_sysimage_path(const char *libname) {
4242
4343void set_depot_load_path (const char * root_dir ) {
4444#ifdef _WIN32
45+ char * path_sep = ";" ;
4546 char * julia_share_subdir = "\\share\\julia" ;
4647#else
48+ char * path_sep = ":" ;
4749 char * julia_share_subdir = "/share/julia" ;
4850#endif
49- char * share_dir =
50- calloc (sizeof (char ), strlen (root_dir ) + strlen (julia_share_subdir ) + 1 );
51- strcat (share_dir , root_dir );
52- strcat (share_dir , julia_share_subdir );
51+ int share_path_len = strlen (root_dir ) + strlen (julia_share_subdir ) + 1 ;
52+
53+ char * curr_depot_path = getenv ("JULIA_DEPOT_PATH" );
54+ int curr_depot_path_len = curr_depot_path == NULL ? 0 : strlen (curr_depot_path );
55+ int new_depot_path_len = curr_depot_path_len + 1 + share_path_len ;
56+ char * new_depot_path = calloc (sizeof (char ), new_depot_path_len );
57+ if (curr_depot_path_len > 0 ) {
58+ strcat (new_depot_path , curr_depot_path );
59+ strcat (new_depot_path , path_sep );
60+ }
61+ strcat (new_depot_path , root_dir );
62+ strcat (new_depot_path , julia_share_subdir );
63+
64+ char * curr_load_path = getenv ("JULIA_LOAD_PATH" );
65+ int curr_load_path_len = curr_load_path == NULL ? 0 : strlen (curr_load_path );
66+ int new_load_path_len = curr_load_path_len + 1 + share_path_len ;
67+ char * new_load_path = calloc (sizeof (char ), new_load_path_len );
68+ if (curr_load_path_len > 0 ) {
69+ strcat (new_load_path , curr_load_path );
70+ strcat (new_load_path , path_sep );
71+ }
72+ strcat (new_load_path , root_dir );
73+ strcat (new_load_path , julia_share_subdir );
5374
5475#ifdef _WIN32
55- _putenv_s ("JULIA_DEPOT_PATH" , share_dir );
56- _putenv_s ("JULIA_LOAD_PATH" , share_dir );
76+ _putenv_s ("JULIA_DEPOT_PATH" , new_depot_path );
77+ _putenv_s ("JULIA_LOAD_PATH" , new_load_path );
5778#else
58- setenv ("JULIA_DEPOT_PATH" , share_dir , 1 );
59- setenv ("JULIA_LOAD_PATH" , share_dir , 1 );
79+ setenv ("JULIA_DEPOT_PATH" , new_depot_path , 1 );
80+ setenv ("JULIA_LOAD_PATH" , new_load_path , 1 );
6081#endif
61- free (share_dir );
82+ free (new_load_path );
83+ free (new_depot_path );
6284}
6385
6486void init_julia (int argc , char * * argv ) {
0 commit comments