comparison src/os/windows/vm/os_windows.cpp @ 691:956304450e80

6819213: revive sun.boot.library.path Summary: Support multiplex and mutable sun.boot.library.path Reviewed-by: acorn, dcubed, xlu
author phh
date Wed, 01 Apr 2009 16:38:01 -0400
parents 6bdd6923ba16
children c8152ae3f339
comparison
equal deleted inserted replaced
690:d142f1feeed5 691:956304450e80
1002 path_buf[0]='\0'; 1002 path_buf[0]='\0';
1003 return path_buf; 1003 return path_buf;
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 void os::dll_build_name(char *holder, size_t holderlen, 1007 static bool file_exists(const char* filename) {
1008 const char* pname, const char* fname) 1008 if (filename == NULL || strlen(filename) == 0) {
1009 { 1009 return false;
1010 // copied from libhpi 1010 }
1011 const size_t pnamelen = pname ? strlen(pname) : 0; 1011 return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES;
1012 const char c = (pnamelen > 0) ? pname[pnamelen-1] : 0; 1012 }
1013 1013
1014 /* Quietly truncates on buffer overflow. Should be an error. */ 1014 void os::dll_build_name(char *buffer, size_t buflen,
1015 if (pnamelen + strlen(fname) + 10 > holderlen) { 1015 const char* pname, const char* fname) {
1016 *holder = '\0'; 1016 // Copied from libhpi
1017 return; 1017 const size_t pnamelen = pname ? strlen(pname) : 0;
1018 } 1018 const char c = (pnamelen > 0) ? pname[pnamelen-1] : 0;
1019 1019
1020 if (pnamelen == 0) { 1020 // Quietly truncates on buffer overflow. Should be an error.
1021 sprintf(holder, "%s.dll", fname); 1021 if (pnamelen + strlen(fname) + 10 > buflen) {
1022 } else if (c == ':' || c == '\\') { 1022 *buffer = '\0';
1023 sprintf(holder, "%s%s.dll", pname, fname); 1023 return;
1024 } else { 1024 }
1025 sprintf(holder, "%s\\%s.dll", pname, fname); 1025
1026 } 1026 if (pnamelen == 0) {
1027 jio_snprintf(buffer, buflen, "%s.dll", fname);
1028 } else if (c == ':' || c == '\\') {
1029 jio_snprintf(buffer, buflen, "%s%s.dll", pname, fname);
1030 } else if (strchr(pname, *os::path_separator()) != NULL) {
1031 int n;
1032 char** pelements = split_path(pname, &n);
1033 for (int i = 0 ; i < n ; i++) {
1034 char* path = pelements[i];
1035 // Really shouldn't be NULL, but check can't hurt
1036 size_t plen = (path == NULL) ? 0 : strlen(path);
1037 if (plen == 0) {
1038 continue; // skip the empty path values
1039 }
1040 const char lastchar = path[plen - 1];
1041 if (lastchar == ':' || lastchar == '\\') {
1042 jio_snprintf(buffer, buflen, "%s%s.dll", path, fname);
1043 } else {
1044 jio_snprintf(buffer, buflen, "%s\\%s.dll", path, fname);
1045 }
1046 if (file_exists(buffer)) {
1047 break;
1048 }
1049 }
1050 // release the storage
1051 for (int i = 0 ; i < n ; i++) {
1052 if (pelements[i] != NULL) {
1053 FREE_C_HEAP_ARRAY(char, pelements[i]);
1054 }
1055 }
1056 if (pelements != NULL) {
1057 FREE_C_HEAP_ARRAY(char*, pelements);
1058 }
1059 } else {
1060 jio_snprintf(buffer, buflen, "%s\\%s.dll", pname, fname);
1061 }
1027 } 1062 }
1028 1063
1029 // Needs to be in os specific directory because windows requires another 1064 // Needs to be in os specific directory because windows requires another
1030 // header file <direct.h> 1065 // header file <direct.h>
1031 const char* os::get_current_directory(char *buf, int buflen) { 1066 const char* os::get_current_directory(char *buf, int buflen) {