From 9784dabb505f736907c17a92885756e4175bd513 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Fri, 25 Apr 2014 18:46:50 +0200 Subject: implemented os_file_get_size() --- src/os/fs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/os/fs.c') diff --git a/src/os/fs.c b/src/os/fs.c index e03d06669d..c245890873 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -189,6 +189,16 @@ int os_file_is_writable(const char *name) return 0; } +bool os_get_file_size(const char *name, off_t *size) +{ + uv_stat_t statbuf; + if (os_stat((char_u *)name, &statbuf) == OK) { + *size = statbuf.st_size; + return true; + } + return false; +} + int os_rename(const char_u *path, const char_u *new_path) { uv_fs_t request; -- cgit From aff96730765a2fc347e30e474bc3049a85758b4d Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Sat, 26 Apr 2014 18:22:07 +0200 Subject: implemented FileInfo struct This struct is a wrapper around `uv_stat_t` to hide the stat information inside `src/os/`. The stat file attribute will be private after all refactorings concerning file informations are done. --- src/os/fs.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/os/fs.c') diff --git a/src/os/fs.c b/src/os/fs.c index c245890873..89eb4c8691 100644 --- a/src/os/fs.c +++ b/src/os/fs.c @@ -237,3 +237,41 @@ int os_remove(const char *path) return result; } +bool os_get_file_info(const char *path, FileInfo *file_info) +{ + if (os_stat((char_u *)path, &(file_info->stat)) == OK) { + return true; + } + return false; +} + +bool os_get_file_info_link(const char *path, FileInfo *file_info) +{ + uv_fs_t request; + int result = uv_fs_lstat(uv_default_loop(), &request, path, NULL); + file_info->stat = request.statbuf; + uv_fs_req_cleanup(&request); + if (result == kLibuvSuccess) { + return true; + } + return false; +} + +bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info) +{ + uv_fs_t request; + int result = uv_fs_fstat(uv_default_loop(), &request, file_descriptor, NULL); + file_info->stat = request.statbuf; + uv_fs_req_cleanup(&request); + if (result == kLibuvSuccess) { + return true; + } + return false; +} + +bool os_file_info_id_equal(FileInfo *file_info_1, FileInfo *file_info_2) +{ + return file_info_1->stat.st_ino == file_info_2->stat.st_ino + && file_info_1->stat.st_dev == file_info_2->stat.st_dev; +} + -- cgit