Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Upgrade libuv to b6ede6c
Browse files Browse the repository at this point in the history
Fixes require('fs').readdirSync on unix.
  • Loading branch information
ry committed Sep 5, 2011
1 parent e20d0c1 commit 01bf209
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion deps/uv/src/unix/fs.c
Expand Up @@ -303,15 +303,26 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
return -1;
}

/* req->result stores number of entries */
req->result = 0;

while ((entry = readdir(dir))) {
d_namlen = strlen(entry->d_name);

/* Skip . and .. */
if ((d_namlen == 1 && entry->d_name[0] == '.') ||
(d_namlen == 2 && entry->d_name[0] == '.' &&
entry->d_name[1] == '.')) {
continue;
}

req->ptr = realloc(req->ptr, size + d_namlen + 1);
/* TODO check ENOMEM */
/* TODO skip . and .. */
memcpy((char*)req->ptr + size, entry->d_name, d_namlen);
size += d_namlen;
((char*)req->ptr)[size] = '\0';
size++;
req->result++;
}

r = closedir(dir);
Expand Down
6 changes: 5 additions & 1 deletion deps/uv/test/test-fs.c
Expand Up @@ -540,6 +540,10 @@ TEST_IMPL(fs_async_dir) {
uv_run(loop);
ASSERT(readdir_cb_count == 1);

/* sync uv_fs_readdir */
r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
readdir_cb(&readdir_req);

r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb);
ASSERT(r == 0);
uv_run(loop);
Expand Down Expand Up @@ -1050,4 +1054,4 @@ TEST_IMPL(fs_symlink) {
unlink("test_file_symlink2_symlink");

return 0;
}
}

0 comments on commit 01bf209

Please sign in to comment.