On Thu, Jun 29, 2006 at 01:32:27PM -0500, Bo Peng wrote:
> OK. Here is the suggested patch that removes the last (?) call to
> shell. Any objection?

Actually, I was trying another solution...
My idea is to query the registry about cygwin. I just tested the
attached source and it works...

Do you want a patch along these lines? I think it is more elegant.

-- 
Enrico
#include <stdio.h>
#include <windows.h>

#define BUFSIZE 80

int main()
{
    HKEY key;
    char cygroot[BUFSIZE];
    DWORD bufSize = sizeof(cygroot);
    LONG retVal;

    retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/usr/bin",
                0, KEY_QUERY_VALUE, &key);

    if (retVal != ERROR_SUCCESS) {
        puts("No cygwin in sight here!");
        exit(0);
    }
    retVal = RegQueryValueEx(key, "native", NULL, NULL,
            (LPBYTE) cygroot, &bufSize);
    RegCloseKey(key);

    if ((retVal != ERROR_SUCCESS) || (bufSize > BUFSIZE)) {
        puts("Cannot find cygwin root dir.");
        exit(0);
    }

    printf("Cygwin root is '%s'\n", cygroot);
    return 0;
}

Reply via email to