diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-04-26 18:22:07 +0200 |
---|---|---|
committer | Stefan Hoffmann <stefan991@gmail.com> | 2014-05-09 15:49:33 +0200 |
commit | aff96730765a2fc347e30e474bc3049a85758b4d (patch) | |
tree | 8cf827ba2977ea2cf982916e6c2a0d56750ccf22 /src | |
parent | 9784dabb505f736907c17a92885756e4175bd513 (diff) | |
download | rneovim-aff96730765a2fc347e30e474bc3049a85758b4d.tar.gz rneovim-aff96730765a2fc347e30e474bc3049a85758b4d.tar.bz2 rneovim-aff96730765a2fc347e30e474bc3049a85758b4d.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/os/fs.c | 38 | ||||
-rw-r--r-- | src/os/os.h | 32 |
2 files changed, 70 insertions, 0 deletions
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; +} + diff --git a/src/os/os.h b/src/os/os.h index 6fa7fbc7ae..b30872f06d 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -111,4 +111,36 @@ char *os_get_user_directory(const char *name); /// @return OK on success, FAIL if an failure occured. int os_stat(const char_u *name, uv_stat_t *statbuf); +/// Struct which encapsulates stat information. +typedef struct { + // TODO(stefan991): make stat private + uv_stat_t stat; +} FileInfo; + +/// Get the file information for a given path +/// +/// @param file_descriptor File descriptor of the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure. +bool os_get_file_info(const char *path, FileInfo *file_info); + +/// Get the file information for a given path without following links +/// +/// @param path Path to the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure. +bool os_get_file_info_link(const char *path, FileInfo *file_info); + +/// Get the file information for a given file descriptor +/// +/// @param file_descriptor File descriptor of the file. +/// @param[out] file_info Pointer to a FileInfo to put the information in. +/// @return `true` on sucess, `false` for failure. +bool os_get_file_info_fd(int file_descriptor, FileInfo *file_info); + +/// Compare the inodes of two FileInfos +/// +/// @return `true` if the two FileInfos represent the same file. +bool os_file_info_id_equal(FileInfo *file_info_1, FileInfo *file_info_2); + #endif // NEOVIM_OS_OS_H |