Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/ctypes/test/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def test_find_library_with_ld(self):
unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: None):
self.assertNotEqual(find_library('c'), None)

def test_gh114257(self):
self.assertIsNone(find_library("libc"))


if __name__ == "__main__":
unittest.main()
7 changes: 5 additions & 2 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ def find_library(name):
def _is_elf(filename):
"Return True if the given file is an ELF file"
elf_header = b'\x7fELF'
with open(filename, 'br') as thefile:
return thefile.read(4) == elf_header
try:
with open(filename, 'br') as thefile:
return thefile.read(4) == elf_header
except FileNotFoundError:
return False

def _findLib_gcc(name):
# Run GCC's linker with the -t (aka --trace) option and examine the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
just return ``None`` on Linux.