Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion libc-bottom-half/cloudlibc/src/libc/unistd/pipe2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <wasi/api.h>
#include <wasi/libc.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

int pipe2(int fd[2], int flag)
Expand All @@ -12,7 +13,28 @@ int pipe2(int fd[2], int flag)
errno = error;
return -1;
}
fd[0] = fd1;

// Set flags if requested
if (flag & O_CLOEXEC) {
Comment thread
zebreus marked this conversation as resolved.
if (fcntl(fd1, F_SETFD, FD_CLOEXEC) < 0 || fcntl(fd2, F_SETFD, FD_CLOEXEC) < 0) {
int saved_errno = errno;
close(fd1);
close(fd2);
errno = saved_errno;
return -1;
}
}
if (flag & O_NONBLOCK) {
if (fcntl(fd1, F_SETFL, O_NONBLOCK) < 0 || fcntl(fd2, F_SETFL, O_NONBLOCK) < 0) {
Comment thread
zebreus marked this conversation as resolved.
Outdated
int saved_errno = errno;
close(fd1);
close(fd2);
Comment thread
zebreus marked this conversation as resolved.
errno = saved_errno;
return -1;
}
Comment thread
zebreus marked this conversation as resolved.
Outdated
}

fd[0] = fd1;
fd[1] = fd2;
return 0;
}