mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
os_scandir(), scandir_next(), and os_closedir()
This commit is contained in:
parent
27ead64da0
commit
99869989c8
@ -348,6 +348,39 @@ int os_rmdir(const char *path)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Opens a directory.
|
||||||
|
/// @param[out] dir The Directory object.
|
||||||
|
/// @param path Path to the directory.
|
||||||
|
/// @returns true if dir contains one or more items, false if not or an error
|
||||||
|
/// occurred.
|
||||||
|
bool os_scandir(Directory *dir, const char *path)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
int r = uv_fs_scandir(uv_default_loop(), &dir->request, path, 0, NULL);
|
||||||
|
if (r <= 0) {
|
||||||
|
os_closedir(dir);
|
||||||
|
}
|
||||||
|
return r > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Increments the directory pointer.
|
||||||
|
/// @param dir The Directory object.
|
||||||
|
/// @returns a pointer to the next path in `dir` or `NULL`.
|
||||||
|
const char *os_scandir_next(Directory *dir)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
int err = uv_fs_scandir_next(&dir->request, &dir->ent);
|
||||||
|
return err != UV_EOF ? dir->ent.name : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Frees memory associated with `os_scandir()`.
|
||||||
|
/// @param dir The directory.
|
||||||
|
void os_closedir(Directory *dir)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
uv_fs_req_cleanup(&dir->request);
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove a file.
|
/// Remove a file.
|
||||||
///
|
///
|
||||||
/// @return `0` for success, non-zero for failure.
|
/// @return `0` for success, non-zero for failure.
|
||||||
|
@ -16,4 +16,9 @@ typedef struct {
|
|||||||
|
|
||||||
#define FILE_ID_EMPTY (FileID) {.inode = 0, .device_id = 0}
|
#define FILE_ID_EMPTY (FileID) {.inode = 0, .device_id = 0}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uv_fs_t request; ///< @private The request to uv for the directory.
|
||||||
|
uv_dirent_t ent; ///< @private The entry information.
|
||||||
|
} Directory;
|
||||||
|
|
||||||
#endif // NVIM_OS_FS_DEFS_H
|
#endif // NVIM_OS_FS_DEFS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user