Skip to content

Commit

Permalink
add jl_get_libjulia_path
Browse files Browse the repository at this point in the history
  • Loading branch information
tknopp committed Dec 20, 2013
1 parent 44501ae commit a2c9c6d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,41 @@ char *jl_dlfind_win32(char *f_name)
// appropriate error.
}
#endif

static char* libjulia_path = NULL;
DLLEXPORT char *jl_get_libjulia_path()
{
if(libjulia_path != NULL)
{
int max_path = 512;
libjulia_path = malloc(max_path);

#ifdef _OS_WINDOWS_

HMODULE hm = NULL;

if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR) &jl_get_libjulia_path,
&hm))
{
int ret = GetLastError();
fprintf(stderr, "GetModuleHandle returned %d\n", ret);
}
GetModuleFileNameA(hm, libjulia_path, max_path);
#else
Dl_info dl_info;
dladdr((void *)jl_get_libjulia_path, &dl_info);
strncpy(libjulia_path, dl_info.dli_fname, max_path);
#endif

// remove libjulia.so/dll/dylib from full path
char * pos = strrchr(libjulia_path, PATHSEP);
if (pos)
{ // terminate string
pos[1] = '\0';
}
}

return libjulia_path;
}
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ DLLEXPORT uv_lib_t *jl_wrap_raw_dl_handle(void *handle);
void *jl_dlsym_e(uv_lib_t *handle, char *symbol); //supress errors
char *jl_dlfind_win32(char *name);
DLLEXPORT int add_library_mapping(char *lib, void *hnd);
DLLEXPORT char *jl_get_libjulia_path();

// event loop
DLLEXPORT void jl_runEventLoop();
Expand Down

0 comments on commit a2c9c6d

Please sign in to comment.