mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-10 04:09:58 +00:00
More robust error handling in windows_getenv. refs #1674
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
7426eccb29
commit
d756ef1765
@ -408,17 +408,23 @@ def windows_getenv(name):
|
||||
raise AssertionError("name must be Unicode")
|
||||
|
||||
n = GetEnvironmentVariableW(name, None, 0)
|
||||
if n <= 0:
|
||||
if n == 0:
|
||||
err = GetLastError()
|
||||
raise OSError("Windows error %d attempting to read environment variable %r"
|
||||
raise OSError("Windows error %d attempting to read size of environment variable %r"
|
||||
% (err, name))
|
||||
elif n < 0:
|
||||
raise OSError("Unexpected result %d from GetEnvironmentVariableW attempting to read size of environment variable %r"
|
||||
% (n, name))
|
||||
|
||||
buf = create_unicode_buffer(u'\0'*n)
|
||||
retval = GetEnvironmentVariableW(name, buf, n)
|
||||
if retval <= 0:
|
||||
if retval == 0:
|
||||
err = GetLastError()
|
||||
raise OSError("Windows error %d attempting to read environment variable %r"
|
||||
% (err, name))
|
||||
elif retval != n-1:
|
||||
raise OSError("Unexpected result %d from GetEnvironmentVariableW attempting to read environment variable %r"
|
||||
% (n, name))
|
||||
|
||||
return buf.value
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user