On Sun, Feb 1, 2015 at 7:53 PM, Rob Stewart
On January 31, 2015 11:29:38 AM EST, Peter Dimov
wrote: Beman Dawes wrote:
The suggested fix is to use GetEnvironmentVariable to in effect implement GetTempPath() the way we would like it to work.
Not that the documented behavior of GetTempPath makes any sense to me - the default temp directory is at %LOCALAPPDATA%\Temp since Win95 or so - but the suggested fix is actually:
"A workaround is to first try to use GetEnvironmentVariable on "TMP" and "TEMP", then fall back on GetTempPath."
You'll have to compare the strings before and after calling GetEnvironmentVariable(). It doesn't indicate whether any substitutions were made and the result could be the same length as the original.
I'm not actually going to fall back to GetTempPath. My tentative implementation using only GetEnvironmentVariable() is much cleaner. See below for the proposed list of env variables.
So, if implemented, it makes
OTOH, excluding the Windows directory is a breaking change for anyone currently depending on that behavior, so I thought it best to ask for comments before charging ahead.
a non-issue, unless you want to avoid calling GetTempPath entirely, in which case I would return %LOCALAPPDATA%\Temp at step 3, obtained via SHGetFolderPath.
+1
SHGetFolderPath is deprecated, and in any case it is very simple and clean just to use a list of directories with GetEnvironmentVariableW(). My current implementation uses this list (shown with the defaults for clean Win 7 and Win 10 installs: TMP=C:\Users\Beman\AppData\Local\Temp TEMP=C:\Users\Beman\AppData\Local\Temp LOCALAPPDATA=C:\Users\Beman\AppData\Local USERPROFILE=C:\Users\Beman Per Peter's suggestion, inserting %LOCALAPPDATA%\Temp would make historic sense. I'm mildly in favor of that. There are two other default environmental variables we could use: SystemRoot=C:\Windows windir=C:\Windows and there are also API functions GetWindowsDirectory and GetSystemWindowsDirectory, but their use is "primarily for compatibility with legacy applications". But I'm against using the Windows directory, however obtained. Thanks, --Beman