diff --git a/main/gbx/gbx_stream.h b/main/gbx/gbx_stream.h index 3dad1b95a..3d5823d36 100644 --- a/main/gbx/gbx_stream.h +++ b/main/gbx/gbx_stream.h @@ -100,6 +100,14 @@ typedef } STREAM_DIRECT; +typedef + struct { + STREAM_COMMON common; + int fd; + unsigned can_write : 1; + } + STREAM_PIPE; + typedef struct { STREAM_COMMON common; @@ -155,7 +163,7 @@ typedef STREAM_RESERVED _reserved; STREAM_DIRECT direct; STREAM_BUFFER buffer; - STREAM_DIRECT pipe; + STREAM_PIPE pipe; STREAM_MEMORY memory; STREAM_ARCH arch; STREAM_PROCESS process; diff --git a/main/gbx/gbx_stream_pipe.c b/main/gbx/gbx_stream_pipe.c index e463c3454..3924bb4b8 100644 --- a/main/gbx/gbx_stream_pipe.c +++ b/main/gbx/gbx_stream_pipe.c @@ -56,19 +56,19 @@ static int stream_open(STREAM *stream, const char *path, int mode) switch (mode & GB_ST_MODE) { - case GB_ST_READ: fmode |= O_RDONLY | O_NONBLOCK; break; + case GB_ST_READ: fmode |= O_RDWR; break; case GB_ST_WRITE: fmode |= O_WRONLY; break; case GB_ST_READ_WRITE: fmode |= O_RDWR; break; - default: fmode |= O_RDONLY; + default: fmode |= O_RDWR; } - RESTART_SYSCALL(fd = open(path, fmode)) + RESTART_SYSCALL(fd = open(path, fmode | O_NONBLOCK)) return TRUE; if ((mode & GB_ST_MODE) == GB_ST_READ) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK); - stream->direct.size = 0; + stream->pipe.can_write = mode & GB_ST_WRITE; FD = fd; return FALSE; @@ -93,6 +93,12 @@ static int stream_read(STREAM *stream, char *buffer, int len) static int stream_write(STREAM *stream, char *buffer, int len) { + if (!stream->pipe.can_write) + { + errno = EBADF; + return -1; + } + return write(FD, buffer, len); }