systemfuncs.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. class SystemFunction(object):
  2. name = None
  3. @classmethod
  4. def getFunctionName(cls):
  5. return cls.name
  6. @classmethod
  7. def getMakeName(cls):
  8. return cls.name.upper()
  9. @classmethod
  10. def iterHeaders(cls, targetPlatform):
  11. raise NotImplementedError
  12. class FTruncateFunction(SystemFunction):
  13. name = 'ftruncate'
  14. @classmethod
  15. def iterHeaders(cls, targetPlatform):
  16. yield '<unistd.h>'
  17. class MMapFunction(SystemFunction):
  18. name = 'mmap'
  19. @classmethod
  20. def iterHeaders(cls, targetPlatform):
  21. if targetPlatform in ('darwin', 'openbsd'):
  22. yield '<sys/types.h>'
  23. yield '<sys/mman.h>'
  24. class PosixMemAlignFunction(SystemFunction):
  25. name = 'posix_memalign'
  26. @classmethod
  27. def iterHeaders(cls, targetPlatform):
  28. yield '<stdlib.h>'
  29. class NftwFunction(SystemFunction):
  30. name = 'nftw'
  31. @classmethod
  32. def iterHeaders(cls, targetPlatform):
  33. yield '<ftw.h>'
  34. # Build a list of system functions using introspection.
  35. systemFunctions = [
  36. obj
  37. for obj in locals().values()
  38. if isinstance(obj, type)
  39. and issubclass(obj, SystemFunction)
  40. and obj is not SystemFunction
  41. ]