diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index de3182bd8b..9453fc4319 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -274,6 +274,12 @@ def test_openssl(): raise ValueError('Mozilla CA certs not loaded') fprint('SSL OK!') +def test_crt(): + from ctypes.util import find_msvcrt + if not find_msvcrt(): + raise SystemExit('find_msvcrt() failed') + fprint('CRT OK!') + def test(): if iswindows: test_dlls() @@ -305,6 +311,7 @@ def test(): test_wpd() test_winutil() test_file_dialog_helper() + test_crt() else: test_terminal() if isosx: diff --git a/src/calibre/utils/terminal.py b/src/calibre/utils/terminal.py index 0632803e18..5581e6fcc8 100644 --- a/src/calibre/utils/terminal.py +++ b/src/calibre/utils/terminal.py @@ -158,9 +158,9 @@ def crt(): # We use the C runtime bundled with the calibre windows build global _crt if _crt is None: - import glob, ctypes - d = os.path.join(os.path.dirname(sys.executable), '*.CRT', 'msvcr*.dll') - _crt = ctypes.CDLL(glob.glob(d)[0]) + import ctypes + from ctypes.util import find_msvcrt + _crt = ctypes.CDLL(find_msvcrt()) return _crt class ColoredStream(Detect):