comparison host/tools/ecostest/common/eCosTest.cpp @ 573:b012f293c30a

* common/eCosTest.cpp (CygPath): Get the cygdrive prefix from the registry.
author jld
date Wed, 05 Feb 2003 13:39:25 +0000
parents 9b55e9c69693
children 74dbf4c3f2e1
comparison
equal deleted inserted replaced
572:028207710cba 573:b012f293c30a
1107 1107
1108 // Convert a path to something a cygwin tool will understand. Used when invoking -size and -gdb 1108 // Convert a path to something a cygwin tool will understand. Used when invoking -size and -gdb
1109 String CeCosTest::CygPath (LPCTSTR pszPath) 1109 String CeCosTest::CygPath (LPCTSTR pszPath)
1110 { 1110 {
1111 #ifdef _WIN32 1111 #ifdef _WIN32
1112 String str; 1112 String str = "";
1113 TCHAR *buf=str.GetBuffer(2+MAX_PATH); 1113 HKEY hKey = 0;
1114 DWORD type;
1115 BYTE value[256];
1116 DWORD sz = sizeof(value);
1117
1118 // look for the cygdrive prefix in the user's registry settings
1119 if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2", 0, KEY_READ, &hKey)) {
1120 if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz)) {
1121 str = (const char*) value;
1122 }
1123 RegCloseKey(hKey);
1124 }
1125
1126 // if not yet found, look for the cygdrive prefix in the system registry settings
1127 hKey = 0;
1128 sz = sizeof(value);
1129 if (str.empty() && (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Cygnus Solutions\\Cygwin\\mounts v2", 0, KEY_READ, &hKey))) {
1130 if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz)) {
1131 str = (const char*) value;
1132 }
1133 RegCloseKey(hKey);
1134 }
1135
1136 int prefixlen = str.length();
1137 TCHAR *buf=str.GetBuffer(prefixlen+1+MAX_PATH);
1114 TCHAR *pszFname; 1138 TCHAR *pszFname;
1115 if(::GetFullPathName(pszPath,MAX_PATH,1+buf, &pszFname)){ 1139 if(::GetFullPathName(pszPath,MAX_PATH,prefixlen+buf, &pszFname)){
1116 GetShortPathName(1+buf,1+buf,MAX_PATH); // ignore errors 1140 GetShortPathName(prefixlen+buf,prefixlen+buf,MAX_PATH); // ignore errors
1117 buf[0]=_TCHAR('/'); 1141 buf[prefixlen+1]=buf[prefixlen];
1118 buf[2]=buf[1]; 1142 buf[prefixlen]=_TCHAR('/');
1119 buf[1]=_TCHAR('/'); 1143 for(int i=prefixlen+2;buf[i];i++){
1120 for(int i=3;buf[i];i++){
1121 if(_TCHAR('\\')==buf[i]){ 1144 if(_TCHAR('\\')==buf[i]){
1122 buf[i]=_TCHAR('/'); 1145 buf[i]=_TCHAR('/');
1123 } 1146 }
1124 } 1147 }
1125 str.ReleaseBuffer(); 1148 str.ReleaseBuffer();