File.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "os/c-api/il2cpp-config-platforms.h"
  2. #if !RUNTIME_TINY
  3. #include "os/File.h"
  4. #include "os/c-api/File-c-api.h"
  5. #include "os/c-api/Allocator.h"
  6. extern "C"
  7. {
  8. UnityPalFileAttributes UnityPalGetFileAttributes(const char* path, int* error)
  9. {
  10. return il2cpp::os::File::GetFileAttributes(path, error);
  11. }
  12. int32_t UnityPalGetFileStat(const char* path, UnityPalFileStat * stat, int* error)
  13. {
  14. il2cpp::os::FileStat cppStat;
  15. bool result = il2cpp::os::File::GetFileStat(path, &cppStat, error);
  16. stat->name = Allocator::CopyToAllocatedStringBuffer(cppStat.name);
  17. stat->attributes = cppStat.attributes;
  18. stat->creation_time = cppStat.creation_time;
  19. stat->last_access_time = cppStat.last_access_time;
  20. stat->last_write_time = cppStat.last_write_time;
  21. stat->length = cppStat.length;
  22. return result;
  23. }
  24. UnityPalFileHandle* UnityPalOpen(const char* path, int openMode, int accessMode, int shareMode, int options, int *error)
  25. {
  26. int localError;
  27. il2cpp::os::FileHandle* handle = il2cpp::os::File::Open(path, openMode, accessMode, shareMode, options, &localError);
  28. if (error != NULL)
  29. *error = localError;
  30. if (localError != il2cpp::os::kErrorCodeSuccess)
  31. return NULL;
  32. return handle;
  33. }
  34. int32_t UnityPalClose(UnityPalFileHandle* handle, int *error)
  35. {
  36. return il2cpp::os::File::Close(handle, error);
  37. }
  38. int UnityPalRead(UnityPalFileHandle* handle, char *dest, int count, int *error)
  39. {
  40. return il2cpp::os::File::Read(handle, dest, count, error);
  41. }
  42. int32_t UnityPalIsExecutable(const char* filename)
  43. {
  44. return il2cpp::os::File::IsExecutable(filename).Get();
  45. }
  46. }
  47. #endif