This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Deriving the Cygwin cygdrive prefix in the eCos configtool


This patch implements registry interrogation to extract the current
Cygwin cygdrive prefix when converting a Windows path to a Cygwin
POSIX-style path in the absence of cygwin1.dll.

John Dallaway
eCosCentric Limited

--cut here--

Index: ecostest/common/eCosTest.cpp
===================================================================
RCS file: /cvs/ecos/ecos/host/tools/ecostest/common/eCosTest.cpp,v
retrieving revision 1.6
diff -u -5 -r1.6 eCosTest.cpp
--- ecostest/common/eCosTest.cpp	23 Nov 2001 17:12:53 -0000	1.6
+++ ecostest/common/eCosTest.cpp	5 Feb 2003 13:31:21 -0000
@@ -1107,19 +1107,42 @@

 // Convert a path to something a cygwin tool will understand.  Used when invoking -size and -gdb
 String CeCosTest::CygPath (LPCTSTR pszPath)
 {
 #ifdef _WIN32
-  String str;
-  TCHAR *buf=str.GetBuffer(2+MAX_PATH);
+  String str = "";
+  HKEY hKey = 0;
+  DWORD type;
+  BYTE value[256];
+  DWORD sz = sizeof(value);
+
+  // look for the cygdrive prefix in the user's registry settings
+  if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2", 0, KEY_READ, &hKey)) {
+    if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz)) {
+      str = (const char*) value;
+    }
+    RegCloseKey(hKey);
+  }
+
+  // if not yet found, look for the cygdrive prefix in the system registry settings
+  hKey = 0;
+  sz = sizeof(value);
+  if (str.empty() && (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Cygnus Solutions\\Cygwin\\mounts v2", 0, KEY_READ, &hKey))) {
+    if (ERROR_SUCCESS == RegQueryValueEx(hKey, "cygdrive prefix", NULL, & type, value, & sz)) {
+      str = (const char*) value;
+    }
+    RegCloseKey(hKey);
+  }
+
+  int prefixlen = str.length();
+  TCHAR *buf=str.GetBuffer(prefixlen+1+MAX_PATH);
   TCHAR *pszFname;
-  if(::GetFullPathName(pszPath,MAX_PATH,1+buf, &pszFname)){
-    GetShortPathName(1+buf,1+buf,MAX_PATH); // ignore errors
-    buf[0]=_TCHAR('/');
-    buf[2]=buf[1];
-    buf[1]=_TCHAR('/');
-    for(int i=3;buf[i];i++){
+  if(::GetFullPathName(pszPath,MAX_PATH,prefixlen+buf, &pszFname)){
+    GetShortPathName(prefixlen+buf,prefixlen+buf,MAX_PATH); // ignore errors
+    buf[prefixlen+1]=buf[prefixlen];
+    buf[prefixlen]=_TCHAR('/');
+    for(int i=prefixlen+2;buf[i];i++){
       if(_TCHAR('\\')==buf[i]){
         buf[i]=_TCHAR('/');
       }
     }
     str.ReleaseBuffer();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]