Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
close_handle = ctypes.windll.kernel32.CloseHandle
h = open_file_win(name)
try:
gfpnbh = ctypes.windll.kernel32.GetFinalPathNameByHandleW
numwchars = 1024
while True:
buf = ctypes.create_unicode_buffer(numwchars)
result = gfpnbh(h, buf, numwchars, 0)
if result == 0:
raise Exception("unknown error while normalizing path")
# The first four chars are //?/
if result <= numwchars:
path = buf.value[4:].replace("\\", "/")
if compat.PYTHON2:
path = path.encode("utf8")
return path
# Not big enough; the result is the amount we need
numwchars = result + 1
finally:
close_handle(h)