##// END OF EJS Templates
pure/osutil: use Python's msvcrt module (issue3380)...
Adrian Buehlmann -
r16474:ee553e6c stable
parent child Browse files
Show More
@@ -58,7 +58,7 b' def listdir(path, stat=False, skip=None)'
58 58 if os.name != 'nt':
59 59 posixfile = open
60 60 else:
61 import ctypes, ctypes.util
61 import ctypes, msvcrt
62 62
63 63 _kernel32 = ctypes.windll.kernel32
64 64
@@ -68,15 +68,6 b' else:'
68 68
69 69 _INVALID_HANDLE_VALUE = _HANDLE(-1).value
70 70
71 def _crtname():
72 try:
73 # find_msvcrt was introduced in Python 2.6
74 return ctypes.util.find_msvcrt()
75 except AttributeError:
76 return 'msvcr71.dll' # CPython 2.5 and 2.4
77
78 _crt = ctypes.PyDLL(_crtname())
79
80 71 # CreateFile
81 72 _FILE_SHARE_READ = 0x00000001
82 73 _FILE_SHARE_WRITE = 0x00000002
@@ -105,9 +96,6 b' else:'
105 96 _DWORD, _DWORD, _HANDLE]
106 97 _kernel32.CreateFileA.restype = _HANDLE
107 98
108 _crt._open_osfhandle.argtypes = [_HANDLE, ctypes.c_int]
109 _crt._open_osfhandle.restype = ctypes.c_int
110
111 99 def _raiseioerror(name):
112 100 err = ctypes.WinError()
113 101 raise IOError(err.errno, '%s: %s' % (name, err.strerror))
@@ -156,10 +144,7 b' else:'
156 144 if fh == _INVALID_HANDLE_VALUE:
157 145 _raiseioerror(name)
158 146
159 # for CPython we must use the same CRT as Python uses,
160 # or the os.fdopen call below will abort with
161 # "OSError: [Errno 9] Bad file descriptor"
162 fd = _crt._open_osfhandle(fh, flags)
147 fd = msvcrt.open_osfhandle(fh, flags)
163 148 if fd == -1:
164 149 _kernel32.CloseHandle(fh)
165 150 _raiseioerror(name)
General Comments 0
You need to be logged in to leave comments. Login now