diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 532e705671..bd5a1a1be5 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -531,11 +531,24 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, DEBUGASSERT(dev); pipe_dumpbuffer("To PIPE:", (FAR uint8_t *)buffer, len); + /* Handle zero-length writes */ + if (len == 0) { return 0; } + /* REVISIT: "If all file descriptors referring to the read end of a pipe + * have been closed, then a write will cause a SIGPIPE signal to be + * generated for the calling process. If the calling process is ignoring + * this signal, then write(2) fails with the error EPIPE." + */ + + if (dev->d_nreaders <= 0) + { + return -EPIPE; + } + /* At present, this method cannot be called from interrupt handlers. That * is because it calls nxsem_wait (via pipecommon_semtake below) and * nxsem_wait cannot be called from interrupt level. This actually