--- a/hotspot/src/os/linux/vm/os_linux.cpp Sun Mar 29 18:19:05 2009 -0400
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Wed Apr 01 16:38:01 2009 -0400
@@ -1518,21 +1518,51 @@
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 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);
}
}