mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
pure/osutil: use Python's msvcrt module (issue3380)
As proposed by Christophe Gouiran <christophe.gouiran@eurocopter.com>
This commit is contained in:
parent
a5b84a16ff
commit
104162e2b1
@ -58,7 +58,7 @@ def listdir(path, stat=False, skip=None):
|
||||
if os.name != 'nt':
|
||||
posixfile = open
|
||||
else:
|
||||
import ctypes, ctypes.util
|
||||
import ctypes, msvcrt
|
||||
|
||||
_kernel32 = ctypes.windll.kernel32
|
||||
|
||||
@ -68,15 +68,6 @@ else:
|
||||
|
||||
_INVALID_HANDLE_VALUE = _HANDLE(-1).value
|
||||
|
||||
def _crtname():
|
||||
try:
|
||||
# find_msvcrt was introduced in Python 2.6
|
||||
return ctypes.util.find_msvcrt()
|
||||
except AttributeError:
|
||||
return 'msvcr71.dll' # CPython 2.5 and 2.4
|
||||
|
||||
_crt = ctypes.PyDLL(_crtname())
|
||||
|
||||
# CreateFile
|
||||
_FILE_SHARE_READ = 0x00000001
|
||||
_FILE_SHARE_WRITE = 0x00000002
|
||||
@ -105,9 +96,6 @@ else:
|
||||
_DWORD, _DWORD, _HANDLE]
|
||||
_kernel32.CreateFileA.restype = _HANDLE
|
||||
|
||||
_crt._open_osfhandle.argtypes = [_HANDLE, ctypes.c_int]
|
||||
_crt._open_osfhandle.restype = ctypes.c_int
|
||||
|
||||
def _raiseioerror(name):
|
||||
err = ctypes.WinError()
|
||||
raise IOError(err.errno, '%s: %s' % (name, err.strerror))
|
||||
@ -156,10 +144,7 @@ else:
|
||||
if fh == _INVALID_HANDLE_VALUE:
|
||||
_raiseioerror(name)
|
||||
|
||||
# for CPython we must use the same CRT as Python uses,
|
||||
# or the os.fdopen call below will abort with
|
||||
# "OSError: [Errno 9] Bad file descriptor"
|
||||
fd = _crt._open_osfhandle(fh, flags)
|
||||
fd = msvcrt.open_osfhandle(fh, flags)
|
||||
if fd == -1:
|
||||
_kernel32.CloseHandle(fh)
|
||||
_raiseioerror(name)
|
||||
|
Loading…
Reference in New Issue
Block a user