Skip to content

Commit f76d986

Browse files
committed
generator: add a find_libc library
Add a way to load the local standard C library. This could be used to load some C standard functions, like *printf ones. This should work on Linux, Windows and macOS/Darwin environments.
1 parent b11669e commit f76d986

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

generator/templates/header.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import os
4646
import sys
4747
import functools
48+
import platform
4849

4950
# Used by EventManager in override.py
5051
import inspect as _inspect
@@ -216,6 +217,22 @@ def find_lib():
216217
# plugin_path used on win32 and MacOS in override.py
217218
dll, plugin_path = find_lib()
218219

220+
def find_libc():
221+
"""Return an instance of the loaded standard C library or None if the
222+
library has not been found.
223+
224+
This function should be compatible with Linux, Windows and macOS.
225+
"""
226+
system = platform.system()
227+
if system == 'Windows':
228+
# On Windows, msvcrt provides MS standard C
229+
return ctypes.cdll.msvcrt
230+
elif system == 'Linux' or system == 'Darwin':
231+
libc_path = find_library('c')
232+
if libc_path is None:
233+
return None
234+
return ctypes.CDLL(libc_path)
235+
219236
class VLCException(Exception):
220237
"""Exception raised by libvlc methods.
221238
"""

0 commit comments

Comments
 (0)