1
0

nxfile.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "nxfile.h"
  2. #include "foundation/error.h"
  3. #include <sys/stat.h>
  4. ns_error_t NXFile_move(nx_uri_t destination, nx_uri_t source)
  5. {
  6. if (!ReplaceFile(destination->string, source->string, 0, 0, 0, 0))
  7. {
  8. if (!MoveFile(source->string, destination->string))
  9. {
  10. if (!CopyFile(source->string, destination->string, FALSE))
  11. {
  12. return NErr_Error;
  13. }
  14. DeleteFile(source->string);
  15. }
  16. }
  17. return NErr_Success;
  18. }
  19. ns_error_t NXFile_unlink(nx_uri_t filename)
  20. {
  21. if (DeleteFile(filename->string))
  22. return NErr_Success;
  23. else
  24. return NErr_Error;
  25. }
  26. ns_error_t NXFile_stat(nx_uri_t filename, nx_file_stat_t file_stats)
  27. {
  28. struct __stat64 buffer;
  29. if (_wstat64(filename->string, &buffer) == 0)
  30. {
  31. file_stats->access_time = buffer.st_atime;
  32. file_stats->creation_time = buffer.st_ctime;
  33. file_stats->modified_time = buffer.st_mtime;
  34. file_stats->file_size = buffer.st_size;
  35. return NErr_Success;
  36. }
  37. else
  38. return NErr_Error;
  39. }
  40. ns_error_t NXFile_statFILE(FILE *f, nx_file_stat_t file_stats)
  41. {
  42. int fd = _fileno(f);
  43. if (fd == -1)
  44. return NErr_Error;
  45. return NXFile_fstat(fd, file_stats);
  46. }
  47. ns_error_t NXFile_fstat(int file_descriptor, nx_file_stat_t file_stats)
  48. {
  49. struct __stat64 buffer;
  50. if (_fstat64(file_descriptor, &buffer) == 0)
  51. {
  52. file_stats->access_time = buffer.st_atime;
  53. file_stats->creation_time = buffer.st_ctime;
  54. file_stats->modified_time = buffer.st_mtime;
  55. file_stats->file_size = buffer.st_size;
  56. return NErr_Success;
  57. }
  58. else
  59. return NErr_Error;
  60. }