summaryrefslogtreecommitdiffstats
path: root/src/unix/pipe.c
diff options
context:
space:
mode:
authorlibuv upstream <libuv@googlegroups.com>2019-01-15 15:42:13 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-16 19:48:27 (GMT)
commit4fcb0d0213112bb2fdb04bb27e82543b93cfe41d (patch)
tree746a72d3795b562075d66fab8947dfd7527b6044 /src/unix/pipe.c
parentc8b67ea119c4000018238f6c3201a1364356d93a (diff)
downloadCMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.zip
CMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.tar.gz
CMake-4fcb0d0213112bb2fdb04bb27e82543b93cfe41d.tar.bz2
libuv 2019-01-15 (f84c5e69)
Code extracted from: https://github.com/libuv/libuv.git at commit f84c5e693b80cb0c62bcefba147e7a66e2b839c9 (v1.x).
Diffstat (limited to 'src/unix/pipe.c')
-rw-r--r--src/unix/pipe.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/unix/pipe.c b/src/unix/pipe.c
index 2c578dc..d3b554c 100644
--- a/src/unix/pipe.c
+++ b/src/unix/pipe.c
@@ -66,8 +66,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)) {
@@ -132,7 +131,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)
@@ -144,9 +156,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);
}
@@ -169,8 +185,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 {
@@ -196,7 +211,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)