Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
unix: map ENAMETOOLONG to UV_ENAMETOOLONG
With tests. Closes #295
  • Loading branch information
mmalecki authored and piscisaureus committed Jan 23, 2012
1 parent edbabe6 commit 24e6c7e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/uv.h
Expand Up @@ -115,7 +115,8 @@ typedef intptr_t ssize_t;
XX( 45, EAISOCKTYPE, "") \
XX( 46, ESHUTDOWN, "") \
XX( 47, EEXIST, "file already exists") \
XX( 48, ESRCH, "no such process")
XX( 48, ESRCH, "no such process") \
XX( 49, ENAMETOOLONG, "name too long")


#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
Expand Down
1 change: 1 addition & 0 deletions src/unix/error.c
Expand Up @@ -71,6 +71,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EFAULT: return UV_EFAULT;
case EMFILE: return UV_EMFILE;
case EMSGSIZE: return UV_EMSGSIZE;
case ENAMETOOLONG: return UV_ENAMETOOLONG;
case EINVAL: return UV_EINVAL;
case ECONNREFUSED: return UV_ECONNREFUSED;
case EADDRINUSE: return UV_EADDRINUSE;
Expand Down
36 changes: 35 additions & 1 deletion test/test-fs.c
Expand Up @@ -45,6 +45,7 @@
# define close _close
#endif

#define TOO_LONG_NAME_LENGTH 8192

typedef struct {
const char* path;
Expand Down Expand Up @@ -416,6 +417,14 @@ static void open_noent_cb(uv_fs_t* req) {
uv_fs_req_cleanup(req);
}

static void open_nametoolong_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ENAMETOOLONG);
ASSERT(req->result == -1);
open_cb_count++;
uv_fs_req_cleanup(req);
}


TEST_IMPL(fs_file_noent) {
uv_fs_t req;
Expand All @@ -441,6 +450,31 @@ TEST_IMPL(fs_file_noent) {
return 0;
}

TEST_IMPL(fs_file_nametoolong) {
uv_fs_t req;
int r;

loop = uv_default_loop();

char name[TOO_LONG_NAME_LENGTH + 1];
memset(name, 'a', TOO_LONG_NAME_LENGTH);
name[TOO_LONG_NAME_LENGTH] = 0;

r = uv_fs_open(loop, &req, name, O_RDONLY, 0, NULL);
ASSERT(r == -1);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENAMETOOLONG);
uv_fs_req_cleanup(&req);

r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb);
ASSERT(r == 0);

ASSERT(open_cb_count == 0);
uv_run(loop);
ASSERT(open_cb_count == 1);

return 0;
}

static void check_utime(const char* path, double atime, double mtime) {
struct stat* s;
Expand Down Expand Up @@ -1543,4 +1577,4 @@ TEST_IMPL(fs_rename_to_existing_file) {
unlink("test_file2");

return 0;
}
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -103,6 +103,7 @@ TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (spawn_and_ping)
TEST_DECLARE (kill)
TEST_DECLARE (fs_file_noent)
TEST_DECLARE (fs_file_nametoolong)
TEST_DECLARE (fs_file_async)
TEST_DECLARE (fs_file_sync)
TEST_DECLARE (fs_async_dir)
Expand Down Expand Up @@ -269,6 +270,7 @@ TASK_LIST_START
#endif

TEST_ENTRY (fs_file_noent)
TEST_ENTRY (fs_file_nametoolong)
TEST_ENTRY (fs_file_async)
TEST_ENTRY (fs_file_sync)
TEST_ENTRY (fs_async_dir)
Expand Down

0 comments on commit 24e6c7e

Please sign in to comment.