diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nx/win/nxfile.c | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nx/win/nxfile.c')
-rw-r--r-- | Src/replicant/nx/win/nxfile.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Src/replicant/nx/win/nxfile.c b/Src/replicant/nx/win/nxfile.c new file mode 100644 index 00000000..dbf79089 --- /dev/null +++ b/Src/replicant/nx/win/nxfile.c @@ -0,0 +1,68 @@ +#include "nxfile.h" +#include "foundation/error.h" +#include <sys/stat.h> +ns_error_t NXFile_move(nx_uri_t destination, nx_uri_t source) +{ + if (!ReplaceFile(destination->string, source->string, 0, 0, 0, 0)) + { + if (!MoveFile(source->string, destination->string)) + { + if (!CopyFile(source->string, destination->string, FALSE)) + { + return NErr_Error; + } + DeleteFile(source->string); + } + } + return NErr_Success; +} + +ns_error_t NXFile_unlink(nx_uri_t filename) +{ + if (DeleteFile(filename->string)) + return NErr_Success; + else + return NErr_Error; +} + +ns_error_t NXFile_stat(nx_uri_t filename, nx_file_stat_t file_stats) +{ + struct __stat64 buffer; + + if (_wstat64(filename->string, &buffer) == 0) + { + file_stats->access_time = buffer.st_atime; + file_stats->creation_time = buffer.st_ctime; + file_stats->modified_time = buffer.st_mtime; + file_stats->file_size = buffer.st_size; + return NErr_Success; + } + else + return NErr_Error; +} + +ns_error_t NXFile_statFILE(FILE *f, nx_file_stat_t file_stats) +{ + int fd = _fileno(f); + if (fd == -1) + return NErr_Error; + + return NXFile_fstat(fd, file_stats); +} + +ns_error_t NXFile_fstat(int file_descriptor, nx_file_stat_t file_stats) +{ + struct __stat64 buffer; + + if (_fstat64(file_descriptor, &buffer) == 0) + { + file_stats->access_time = buffer.st_atime; + file_stats->creation_time = buffer.st_ctime; + file_stats->modified_time = buffer.st_mtime; + file_stats->file_size = buffer.st_size; + return NErr_Success; + } + else + return NErr_Error; +} + |