rust9x / rust

Empowering everyone to build reliable and efficient software, even for Windows 9x/Me/NT/2000/XP/Vista.
https://github.com/rust9x/rust/wiki
Other
334 stars 10 forks source link

`home_dir` returns Some("") instead of None on NT 3.51 #1

Open seritools opened 2 years ago

seritools commented 2 years ago

Environment variables in general should probably be checked a bit closer. GetEnvironmentVariableW might behave slightly differently on old Windows versions.

MSDN VC6:

If the function succeeds, the return value is the number of characters stored into the buffer pointed to by lpBuffer, not including the terminating null character. If the specified environment variable name was not found in the environment block for the current process, the return value is zero. If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in characters, required to hold the value string and its terminating null character.

MSDN 2005:

If the function succeeds, the return value is the number of characters stored in the buffer pointed to by lpBuffer, not including the terminating null character. If lpBuffer is not large enough to hold the data, the return value is the buffer size, in characters, required to hold the string and its terminating null character. If the function fails, the return value is zero. If the specified environment variable was not found in the environment block, GetLastError returns ERROR_ENVVAR_NOT_FOUND.

It might be that ERROR_ENVVAR_NOT_FOUND didn't exist yet. On NT 3.51, HOME/USERPROFILE didn't exist yet, but HOMEDRIVE (only drive letter) and HOMEPATH do.