pal_time.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "il2cpp-config.h"
  2. #include "pal_platform.h"
  3. #if IL2CPP_USES_POSIX_CLASS_LIBRARY_PAL
  4. struct TimeValPair;
  5. #include <sys/time.h>
  6. #include <errno.h>
  7. extern "C"
  8. {
  9. // Items needed by mscorlib
  10. IL2CPP_EXPORT int32_t SystemNative_UTimes(const char* path, TimeValPair* times);
  11. }
  12. typedef struct TimeValPair
  13. {
  14. int64_t AcTimeSec;
  15. int64_t AcTimeUSec;
  16. int64_t ModTimeSec;
  17. int64_t ModTimeUSec;
  18. } TimeValPair;
  19. static void ConvertTimeValPair(const TimeValPair* pal, struct timeval native[2])
  20. {
  21. native[0].tv_sec = (long)(pal->AcTimeSec);
  22. native[0].tv_usec = (long)(pal->AcTimeUSec);
  23. native[1].tv_sec = (long)(pal->ModTimeSec);
  24. native[1].tv_usec = (long)(pal->ModTimeUSec);
  25. }
  26. template<typename TInt>
  27. static inline bool CheckInterrupted(TInt result)
  28. {
  29. return result < 0 && errno == EINTR;
  30. }
  31. int32_t SystemNative_UTimes(const char* path, TimeValPair* times)
  32. {
  33. IL2CPP_ASSERT(times != NULL);
  34. struct timeval temp[2];
  35. ConvertTimeValPair(times, temp);
  36. int32_t result;
  37. while (CheckInterrupted(result = utimes_(path, temp)))
  38. ;
  39. return result;
  40. }
  41. #endif