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:
Stefan Hoffmann
2014-04-26 18:22:07 +02:00
parent 9784dabb50
commit aff9673076
3 changed files with 172 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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