diff options
Diffstat (limited to 'src/libstddjb/fd_ensure_open.c')
-rw-r--r-- | src/libstddjb/fd_ensure_open.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libstddjb/fd_ensure_open.c b/src/libstddjb/fd_ensure_open.c index c42c90e..4c1b63c 100644 --- a/src/libstddjb/fd_ensure_open.c +++ b/src/libstddjb/fd_ensure_open.c @@ -2,18 +2,19 @@ #include <errno.h> #include <fcntl.h> + #include <skalibs/djbunix.h> int fd_ensure_open (int fd, int w) { int dummy ; - if (fcntl(fd, F_GETFD, &dummy) < 0) + if (fcntl(fd, F_GETFD, &dummy) == -1) { int newfd ; if (errno != EBADF) return 0 ; newfd = open2("/dev/null", w ? O_WRONLY : O_RDONLY) ; - if (newfd < 0) return 0 ; - if (fd_move(fd, newfd) < 0) + if (newfd == -1) return 0 ; + if (fd_move(fd, newfd) == -1) { fd_close(newfd) ; return 0 ; |