Skip to content

Instantly share code, notes, and snippets.

@misterdjules
Created October 10, 2014 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterdjules/4473216b184b7728364f to your computer and use it in GitHub Desktop.
Save misterdjules/4473216b184b7728364f to your computer and use it in GitHub Desktop.
uv_fs_opendir for win32
diff --git a/include/uv.h b/include/uv.h
index 601a7f1..86516a9 100644
--- a/include/uv.h
+++ b/include/uv.h
@@ -1045,6 +1045,7 @@ typedef enum {
struct uv_dir_s {
UV_HANDLE_FIELDS
+ int dir_flags;
UV_DIR_PRIVATE_FIELDS
};
@@ -1121,14 +1122,15 @@ UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
*/
#define UV_DIR_FLAGS_NONE 0
-/* uv_fs_{open,readdir} are not yet implemented on Windows */
-#ifndef _WIN32
+
UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
uv_fs_t* req,
uv_dir_t* dirh,
const char* path,
int flags,
uv_fs_cb cb);
+#ifndef _WIN32
+/* uv_fs_readdir is not yet implemented on Windows */
UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
uv_fs_t* req,
uv_dir_t* dirh,
diff --git a/src/unix/fs.c b/src/unix/fs.c
index 2687cdb..6de3214 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -1155,7 +1155,7 @@ int uv_fs_opendir(uv_loop_t* loop,
uv__handle_init(loop, dirh, UV_DIR);
- req->flags = flags;
+ dirh->dir_flags = flags;
dirh->dir = NULL;
req->dir_handle = dirh;
diff --git a/src/win/fs.c b/src/win/fs.c
index 4c319db..f4719f8 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -1861,6 +1861,32 @@ int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
}
}
+int uv_fs_opendir(uv_loop_t* loop,
+ uv_fs_t* req,
+ uv_dir_t* dirh,
+ const char* path,
+ int flags,
+ uv_fs_cb cb) {
+ int err;
+
+ uv_fs_req_init(loop, req, UV_FS_OPENDIR, cb);
+
+ err = fs__capture_path(loopm req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
+
+ dirh->dir_flags = flags;
+
+ if (cb) {
+ QUEUE_FS_TP_JOB(loop, req);
+ return 0;
+ } else {
+ fs__opendir(req);
+ return req->result;
+ }
+}
+
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment