Add a fallback to `libc.so` library name to fix loading the ctypes
implementation on musl systems. On musl, `find_library("c")` does
not work (the problem has been reported to CPython in 2014, and has not
been resolved yet), causing the module to fail on `assert libcname`.
Instead, add a fallback to using `libc.so` and let ctypes raise
an exception if such a library does not exist.
if sys.platform == "linux":
libcname = ctypes.util.find_library("c")
- assert libcname
+ if not libcname:
+ # Likely this is a system using musl libc, see the following bug:
+ # https://github.com/python/cpython/issues/65821
+ libcname = "libc.so"
libc = ctypes.cdll.LoadLibrary(libcname)
fdopen = libc.fdopen