mercurial/pure/osutil.py
changeset 19465 004f965630d9
parent 18959 2f6418d8a4c9
child 25645 977102cb12fc
equal deleted inserted replaced
19464:68f7129af6a8 19465:004f965630d9
    57 
    57 
    58 if os.name != 'nt':
    58 if os.name != 'nt':
    59     posixfile = open
    59     posixfile = open
    60 else:
    60 else:
    61     import ctypes, msvcrt
    61     import ctypes, msvcrt
       
    62     from errno import ESRCH, ENOENT
    62 
    63 
    63     _kernel32 = ctypes.windll.kernel32
    64     _kernel32 = ctypes.windll.kernel32
    64 
    65 
    65     _DWORD = ctypes.c_ulong
    66     _DWORD = ctypes.c_ulong
    66     _LPCSTR = _LPSTR = ctypes.c_char_p
    67     _LPCSTR = _LPSTR = ctypes.c_char_p
    96         _DWORD, _DWORD, _HANDLE]
    97         _DWORD, _DWORD, _HANDLE]
    97     _kernel32.CreateFileA.restype = _HANDLE
    98     _kernel32.CreateFileA.restype = _HANDLE
    98 
    99 
    99     def _raiseioerror(name):
   100     def _raiseioerror(name):
   100         err = ctypes.WinError()
   101         err = ctypes.WinError()
   101         raise IOError(err.errno, '%s: %s' % (name, err.strerror))
   102         # For python 2.4, treat ESRCH as ENOENT like WindowsError does
       
   103         # in python 2.5 or later.
       
   104         # py24:           WindowsError(3, '').errno => 3
       
   105         # py25 or later:  WindowsError(3, '').errno => 2
       
   106         errno = err.errno
       
   107         if errno == ESRCH:
       
   108             errno = ENOENT
       
   109         raise IOError(errno, '%s: %s' % (name, err.strerror))
   102 
   110 
   103     class posixfile(object):
   111     class posixfile(object):
   104         '''a file object aiming for POSIX-like semantics
   112         '''a file object aiming for POSIX-like semantics
   105 
   113 
   106         CPython's open() returns a file that was opened *without* setting the
   114         CPython's open() returns a file that was opened *without* setting the