aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/fs.c
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-05-10 11:49:25 +0200
committerStefan Hoffmann <stefan991@gmail.com>2014-06-27 13:59:28 +0200
commit4a22fb06b98fedd0e95d2bb4529ac1d74c418ff4 (patch)
tree3ec1ef2858dd9fb17ad7103dd0b7173a0c37b205 /src/nvim/os/fs.c
parent8a85b37253ccb3aa9e127a53f5a0c0ee80cd65d7 (diff)
downloadrneovim-4a22fb06b98fedd0e95d2bb4529ac1d74c418ff4.tar.gz
rneovim-4a22fb06b98fedd0e95d2bb4529ac1d74c418ff4.tar.bz2
rneovim-4a22fb06b98fedd0e95d2bb4529ac1d74c418ff4.zip
FileID: implement `FileID` struct
`FileID` should encapsulate `st_dev` and `st_ino`. It is a new abstraction used to check if two files are the same. `FileID`s will be embeded inside other struts like `buf_t` or `ff_visited_T`, where a full `FileInfo` would be to big.
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r--src/nvim/os/fs.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index c8408d78e4..e0e2fbf3c3 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -345,8 +345,69 @@ 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)
+bool os_file_info_id_equal(const FileInfo *file_info_1,
+ const 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;
}
+
+/// Get the `FileID` of a `FileInfo`
+///
+/// @param file_info Pointer to the `FileInfo`
+/// @param[out] file_id Pointer to a `FileID`
+void os_file_info_get_id(const FileInfo *file_info, FileID *file_id)
+{
+ file_id->inode = file_info->stat.st_ino;
+ file_id->device_id = file_info->stat.st_dev;
+}
+
+/// Get the inode of a `FileInfo`
+///
+/// @deprecated Use `FileID` instead, this function is only needed in memline.c
+/// @param file_info Pointer to the `FileInfo`
+/// @return the inode number
+uint64_t os_file_info_get_inode(const FileInfo *file_info)
+{
+ return file_info->stat.st_ino;
+}
+
+/// Get the `FileID` for a given path
+///
+/// @param path Path to the file.
+/// @param[out] file_info Pointer to a `FileID` to fill in.
+/// @return `true` on sucess, `false` for failure.
+bool os_get_file_id(const char *path, FileID *file_id)
+{
+ uv_stat_t statbuf;
+ if (os_stat((char_u *)path, &statbuf) == OK) {
+ file_id->inode = statbuf.st_ino;
+ file_id->device_id = statbuf.st_dev;
+ return true;
+ }
+ return false;
+}
+
+/// Check if two `FileID`s are equal
+///
+/// @param file_id_1 Pointer to first `FileID`
+/// @param file_id_2 Pointer to second `FileID`
+/// @return `true` if the two `FileID`s represent te same file.
+bool os_file_id_equal(const FileID *file_id_1, const FileID *file_id_2)
+{
+ return file_id_1->inode == file_id_2->inode
+ && file_id_1->device_id == file_id_2->device_id;
+}
+
+/// Check if a `FileID` is equal to a `FileInfo`
+///
+/// @param file_id Pointer to a `FileID`
+/// @param file_info Pointer to a `FileInfo`
+/// @return `true` if the `FileID` and the `FileInfo` represent te same file.
+bool os_file_id_equal_file_info(const FileID *file_id,
+ const FileInfo *file_info)
+{
+ return file_id->inode == file_info->stat.st_ino
+ && file_id->device_id == file_info->stat.st_dev;
+}
+