summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/unix/pipe.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-16 20:00:33 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-17 15:26:32 (GMT)
commit1e1209729b26312cb511d5995bd57b6f5d35235e (patch)
tree8fb1927e363a9278f103a9a70a5a7923d398cbaf /Utilities/cmlibuv/src/unix/pipe.c
parentc59eae7ebc5423c2b06befd762f8639b0f23b7a0 (diff)
parent4fcb0d0213112bb2fdb04bb27e82543b93cfe41d (diff)
downloadCMake-1e1209729b26312cb511d5995bd57b6f5d35235e.zip
CMake-1e1209729b26312cb511d5995bd57b6f5d35235e.tar.gz
CMake-1e1209729b26312cb511d5995bd57b6f5d35235e.tar.bz2
Merge branch 'upstream-libuv' into update-libuv
* upstream-libuv: libuv 2019-01-15 (f84c5e69)
Diffstat (limited to 'Utilities/cmlibuv/src/unix/pipe.c')
-rw-r--r--Utilities/cmlibuv/src/unix/pipe.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/Utilities/cmlibuv/src/unix/pipe.c b/Utilities/cmlibuv/src/unix/pipe.c
index 42846b9..9657bc9 100644
--- a/Utilities/cmlibuv/src/unix/pipe.c
+++ b/Utilities/cmlibuv/src/unix/pipe.c
@@ -64,8 +64,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
sockfd = err;
memset(&saddr, 0, sizeof saddr);
- strncpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path) - 1);
- saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
+ uv__strscpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
@@ -130,7 +129,20 @@ void uv__pipe_close(uv_pipe_t* handle) {
int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
+ int flags;
+ int mode;
int err;
+ flags = 0;
+
+ if (uv__fd_exists(handle->loop, fd))
+ return UV_EEXIST;
+
+ do
+ mode = fcntl(fd, F_GETFL);
+ while (mode == -1 && errno == EINTR);
+
+ if (mode == -1)
+ return UV__ERR(errno); /* according to docs, must be EBADF */
err = uv__nonblock(fd, 1);
if (err)
@@ -142,9 +154,13 @@ int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
return err;
#endif /* defined(__APPLE__) */
- return uv__stream_open((uv_stream_t*)handle,
- fd,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ mode &= O_ACCMODE;
+ if (mode != O_WRONLY)
+ flags |= UV_HANDLE_READABLE;
+ if (mode != O_RDONLY)
+ flags |= UV_HANDLE_WRITABLE;
+
+ return uv__stream_open((uv_stream_t*)handle, fd, flags);
}
@@ -167,8 +183,7 @@ void uv_pipe_connect(uv_connect_t* req,
}
memset(&saddr, 0, sizeof saddr);
- strncpy(saddr.sun_path, name, sizeof(saddr.sun_path) - 1);
- saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
+ uv__strscpy(saddr.sun_path, name, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
do {
@@ -194,7 +209,7 @@ void uv_pipe_connect(uv_connect_t* req,
if (new_sock) {
err = uv__stream_open((uv_stream_t*)handle,
uv__stream_fd(handle),
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
}
if (err == 0)