1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-01 04:19:55 +00:00

Add windows implementation for piping.

This commit is contained in:
Calvin Rose 2020-09-12 19:56:48 -05:00
parent d3147b661b
commit 524c9b50d4

View File

@ -418,12 +418,18 @@ static Janet os_proc_kill(int32_t argc, Janet *argv) {
static JanetFile *make_pipes(JanetHandle *handle, int reverse) { static JanetFile *make_pipes(JanetHandle *handle, int reverse) {
JanetHandle handles[2]; JanetHandle handles[2];
#ifdef JANET_WINDOWS #ifdef JANET_WINDOWS
bool result = CreatePipe(handles, handles + 1, NULL, 0); if (!CreatePipe(handles, handles + 1, NULL, 0)) janet_panic("failed to create pipe");
if (result) { if (reverse) {
JanetHandle temp = handles[0];
} else { handles[0] = handles[1];
handles[1] = temp;
} }
*handle = handles[1];
int fd = _open_osfhandle((intptr_t) handles[0], reverse ? _O_WRONLY : _O_RDONLY);
if (fd == -1) janet_panic("could not create file for piping");
FILE *f = _fdopen(fd, reverse ? "w" : "r");
if (NULL == f) janet_panic(strerror(errno));
return janet_makejfile(f, reverse ? JANET_FILE_WRITE : JANET_FILE_READ);
#else #else
if (pipe(handles)) janet_panic(strerror(errno)); if (pipe(handles)) janet_panic(strerror(errno));
if (reverse) { if (reverse) {