Skip to content
Snippets Groups Projects
Commit 1ef95b99 authored by Alexander Turenko's avatar Alexander Turenko Committed by Kirill Yukhin
Browse files

popen: remove redundant fd check before perform IO


The function already checks flags to find out whether the file
descriptor should be available for reading / writing. When it is so, the
corresponding fd is great or equal to zero.

The further commits will add missed diagnostics for IO functions and it
is hard to write a meaningful error message for a situation that is not
possible. Moreover, we would obligated to document the error as one of
possible failures in a function contract (while it can't occur).

Part of #4031

Acked-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 631f5f37
No related branches found
No related tags found
No related merge requests found
...@@ -193,8 +193,7 @@ handle_free(struct popen_handle *handle) ...@@ -193,8 +193,7 @@ handle_free(struct popen_handle *handle)
* Test if the handle can run io operation. * Test if the handle can run io operation.
*/ */
static inline bool static inline bool
popen_may_io(struct popen_handle *handle, unsigned int idx, popen_may_io(struct popen_handle *handle, unsigned int io_flags)
unsigned int io_flags)
{ {
if (!handle) { if (!handle) {
errno = ESRCH; errno = ESRCH;
...@@ -206,11 +205,6 @@ popen_may_io(struct popen_handle *handle, unsigned int idx, ...@@ -206,11 +205,6 @@ popen_may_io(struct popen_handle *handle, unsigned int idx,
return false; return false;
} }
if (handle->ios[idx].fd < 0) {
errno = EPIPE;
return false;
}
return true; return true;
} }
...@@ -293,7 +287,7 @@ popen_write_timeout(struct popen_handle *handle, const void *buf, ...@@ -293,7 +287,7 @@ popen_write_timeout(struct popen_handle *handle, const void *buf,
return -1; return -1;
} }
if (!popen_may_io(handle, STDIN_FILENO, flags)) if (!popen_may_io(handle, flags))
return -1; return -1;
if (count > (size_t)SSIZE_MAX) { if (count > (size_t)SSIZE_MAX) {
...@@ -328,7 +322,7 @@ popen_read_timeout(struct popen_handle *handle, void *buf, ...@@ -328,7 +322,7 @@ popen_read_timeout(struct popen_handle *handle, void *buf,
return -1; return -1;
} }
if (!popen_may_io(handle, idx, flags)) if (!popen_may_io(handle, flags))
return -1; return -1;
if (count > (size_t)SSIZE_MAX) { if (count > (size_t)SSIZE_MAX) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment