@@ -46,19 +46,39 @@ void set_depot_load_path(const char *root_dir) {
4646#else
4747 char * julia_share_subdir = "/share/julia" ;
4848#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 );
49+ int share_path_len = strlen (root_dir ) + strlen (julia_share_subdir ) + 1 ;
50+
51+ char * curr_depot_path = getenv ("JULIA_DEPOT_PATH" );
52+ int curr_depot_path_len = curr_depot_path == NULL ? 0 : strlen (curr_depot_path );
53+ int new_depot_path_len = curr_depot_path_len + 1 + share_path_len ;
54+ char * new_depot_path = calloc (sizeof (char ), new_depot_path_len );
55+ if (curr_depot_path_len > 0 ) {
56+ strcat (new_depot_path , curr_depot_path );
57+ strcat (new_depot_path , ":" );
58+ }
59+ strcat (new_depot_path , root_dir );
60+ strcat (new_depot_path , julia_share_subdir );
61+
62+ char * curr_load_path = getenv ("JULIA_LOAD_PATH" );
63+ int curr_load_path_len = curr_load_path == NULL ? 0 : strlen (curr_load_path );
64+ int new_load_path_len = curr_load_path_len + 1 + share_path_len ;
65+ char * new_load_path = calloc (sizeof (char ), new_load_path_len );
66+ if (curr_load_path_len > 0 ) {
67+ strcat (new_load_path , curr_load_path );
68+ strcat (new_load_path , ":" );
69+ }
70+ strcat (new_load_path , root_dir );
71+ strcat (new_load_path , julia_share_subdir );
5372
5473#ifdef _WIN32
55- _putenv_s ("JULIA_DEPOT_PATH" , share_dir );
56- _putenv_s ("JULIA_LOAD_PATH" , share_dir );
74+ _putenv_s ("JULIA_DEPOT_PATH" , new_depot_path );
75+ _putenv_s ("JULIA_LOAD_PATH" , new_load_path );
5776#else
58- setenv ("JULIA_DEPOT_PATH" , share_dir , 1 );
59- setenv ("JULIA_LOAD_PATH" , share_dir , 1 );
77+ setenv ("JULIA_DEPOT_PATH" , new_depot_path , 1 );
78+ setenv ("JULIA_LOAD_PATH" , new_load_path , 1 );
6079#endif
61- free (share_dir );
80+ free (new_load_path );
81+ free (new_depot_path );
6282}
6383
6484void init_julia (int argc , char * * argv ) {
0 commit comments