2014-06-21 01:09:22 +00:00
|
|
|
import ffi
|
2014-09-06 16:36:28 +00:00
|
|
|
import sys
|
2014-06-21 01:09:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
_h = None
|
|
|
|
|
2021-05-27 05:50:04 +00:00
|
|
|
names = ("libc.so", "libc.so.0", "libc.so.6", "libc.dylib")
|
|
|
|
|
2014-06-21 01:09:22 +00:00
|
|
|
|
|
|
|
def get():
|
|
|
|
global _h
|
|
|
|
if _h:
|
|
|
|
return _h
|
|
|
|
err = None
|
|
|
|
for n in names:
|
|
|
|
try:
|
|
|
|
_h = ffi.open(n)
|
|
|
|
return _h
|
|
|
|
except OSError as e:
|
|
|
|
err = e
|
|
|
|
raise err
|
|
|
|
|
|
|
|
|
|
|
|
def set_names(n):
|
|
|
|
global names
|
|
|
|
names = n
|
2014-09-06 16:36:28 +00:00
|
|
|
|
2021-05-27 05:50:04 +00:00
|
|
|
|
2014-09-06 16:36:28 +00:00
|
|
|
# Find out bitness of the platform, even if long ints are not supported
|
|
|
|
# TODO: All bitness differences should be removed from micropython-lib, and
|
|
|
|
# this snippet too.
|
|
|
|
bitness = 1
|
|
|
|
v = sys.maxsize
|
|
|
|
while v:
|
|
|
|
bitness += 1
|
|
|
|
v >>= 1
|