4

I have some Python code that uses a library that implements virtual file systems. For the drivers for those virtual file systems to work a bunch of C functions (like readdir(), opendir(), fseek()) need to be overridden/replaced - with the replacements defined in a .so/.cpp file. Usually this could be done by setting LD_PRELOAD to that .so file. However, I need to be able to override these functions at runtime, and ideally revert back to the non-overridden functions once the Python functions that use those overridden functions have executed. Is this possible?

1 Answer 1

2

I am guessing you want ctypes. Here is a discussion: https://docs.python.org/2/library/ctypes.html

Sign up to request clarification or add additional context in comments.

3 Comments

This looks very promising, thank you. I'll mark it as the answer once I figure out how to make the functions in the os module in Python use the library I imported using ctypes!
Usually these kinds of things are coded in C or C++. And linked into a shared library.
That makes sense, but I need to work with an existing Python code base. I have a .cpp/.so file with all the redefinitions that the Python os functions should use, which is part of a C++ library that has Python wrappers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.