mirror of
https://github.com/neovim/neovim.git
synced 2026-08-28 18:11:47 +00:00
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.
This commit is contained in:
38
src/os/fs.c
38
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;
|
||||
}
|
||||
|
||||
|
||||
32
src/os/os.h
32
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
|
||||
|
||||
Reference in New Issue
Block a user