| 1 | diff -ru Python-2.7.12.orig/Lib/ctypes/util.py Python-2.7.12/Lib/ctypes/util.py
|
| 2 | |
| 3 | |
| 4 | @@ -204,6 +204,41 @@
|
| 5 | def find_library(name, is64 = False):
|
| 6 | return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
|
| 7 |
|
| 8 | + elif True:
|
| 9 | +
|
| 10 | + # Patched for Alpine Linux / musl - search manually system paths
|
| 11 | + def _is_elf(filepath):
|
| 12 | + try:
|
| 13 | + with open(filepath, 'rb') as fh:
|
| 14 | + return fh.read(4) == b'\x7fELF'
|
| 15 | + except:
|
| 16 | + return False
|
| 17 | +
|
| 18 | + def find_library(name):
|
| 19 | + from glob import glob
|
| 20 | + # absolute name?
|
| 21 | + if os.path.isabs(name):
|
| 22 | + return name
|
| 23 | + # special case for libm, libcrypt and libpthread and musl
|
| 24 | + if name in ['m', 'crypt', 'pthread']:
|
| 25 | + name = 'c'
|
| 26 | + elif name in ['libm.so', 'libcrypt.so', 'libpthread.so']:
|
| 27 | + name = 'libc.so'
|
| 28 | + # search in standard locations (musl order)
|
| 29 | + paths = ['/lib', '/usr/local/lib', '/usr/lib']
|
| 30 | + if 'LD_LIBRARY_PATH' in os.environ:
|
| 31 | + paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths
|
| 32 | + for d in paths:
|
| 33 | + f = os.path.join(d, name)
|
| 34 | + if _is_elf(f):
|
| 35 | + return os.path.basename(f)
|
| 36 | +
|
| 37 | + prefix = os.path.join(d, 'lib'+name)
|
| 38 | + for suffix in ['.so', '.so.*']:
|
| 39 | + for f in glob('{0}{1}'.format(prefix, suffix)):
|
| 40 | + if _is_elf(f):
|
| 41 | + return os.path.basename(f)
|
| 42 | +
|
| 43 | else:
|
| 44 |
|
| 45 | def _findSoname_ldconfig(name):
|