diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 1881e89..0f2a640 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -203,14 +203,17 @@ elif os.name == "posix": abi_type = mach_map.get(machine, 'libc6') # XXX assuming GLIBC's ldconfig (with option -p) - expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \ - % (abi_type, re.escape(name)) + name = 'lib%s' % name with contextlib.closing(os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')) as f: - data = f.read() - res = re.search(expr, data) - if not res: - return None - return res.group(1) + for line in f: + if not '=>' in line: + continue + path = line.rsplit('=>', 1)[1] + if not name+'.' in path: + continue + res = re.search('\s*(/[^\(\)\s]*%s\.[^\(\)\s]*)' % re.escape(name), path) + if res: + return res.group(1) def find_library(name): return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))