6819213: revive sun.boot.library.path

Support multiplex and mutable sun.boot.library.path

Reviewed-by: acorn, dcubed, xlu
This commit is contained in:
Paul Hohensee 2009-04-01 16:38:01 -04:00
parent d37d544754
commit 4be7c3c672
9 changed files with 345 additions and 50 deletions

View file

@ -1827,21 +1827,51 @@ const char* os::dll_file_extension() { return ".so"; }
const char* os::get_temp_directory() { return "/tmp/"; }
void os::dll_build_name(
char* buffer, size_t buflen, const char* pname, const char* fname) {
// copied from libhpi
static bool file_exists(const char* filename) {
struct stat statbuf;
if (filename == NULL || strlen(filename) == 0) {
return false;
}
return os::stat(filename, &statbuf) == 0;
}
void os::dll_build_name(char* buffer, size_t buflen,
const char* pname, const char* fname) {
// Copied from libhpi
const size_t pnamelen = pname ? strlen(pname) : 0;
/* Quietly truncate on buffer overflow. Should be an error. */
// Quietly truncate on buffer overflow. Should be an error.
if (pnamelen + strlen(fname) + 10 > (size_t) buflen) {
*buffer = '\0';
return;
}
if (pnamelen == 0) {
sprintf(buffer, "lib%s.so", fname);
snprintf(buffer, buflen, "lib%s.so", fname);
} else if (strchr(pname, *os::path_separator()) != NULL) {
int n;
char** pelements = split_path(pname, &n);
for (int i = 0 ; i < n ; i++) {
// really shouldn't be NULL but what the heck, check can't hurt
if (pelements[i] == NULL || strlen(pelements[i]) == 0) {
continue; // skip the empty path values
}
snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname);
if (file_exists(buffer)) {
break;
}
}
// release the storage
for (int i = 0 ; i < n ; i++) {
if (pelements[i] != NULL) {
FREE_C_HEAP_ARRAY(char, pelements[i]);
}
}
if (pelements != NULL) {
FREE_C_HEAP_ARRAY(char*, pelements);
}
} else {
sprintf(buffer, "%s/lib%s.so", pname, fname);
snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
}
}