[bt-devel] Windows Module Install bug

Matthew Talbert ransom1982 at gmail.com
Tue Apr 21 19:26:17 MST 2009


>   SWBuf homeDir = getenv("HOME");
>   if (!homeDir.length()) {
>       // silly windows
>       homeDir = getenv("HOMEDRIVE");
>       if (homeDir.length()) {
>           homeDir += getenv("HOMEPATH");
>           homeDir += "/Application Data";
>       }


There is a much simpler and more correct way of getting this directory:

homeDir = getenv("APPDATA")

It is more correct, because "Application Data" is localized, and thus
won't appear in localized versions of Windows, while APPDATA always
contains the localized version. Of course, getenv is wrong because it
really needs to be using the Windows API calls to get the correct
value, but hopefully that will be fixed sometime.

(There are two problems with getenv; the first is that if the
environment variable contains symbols that aren't representable in the
encoding used by the C runtime, it will not get the correct result.
The second is that environment variables on Windows can be nested, so
you should either use the Windows methods or carefully look at the
return values to make sure that they don't contain variables
themselves.)

All of this should ideally be discussed on sword-devel as there are
other considerations as well. I have been waiting until after 1.6 is
released to bring it up.

Matthew



More information about the bt-devel mailing list