]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - src/coloredstderr.c
fcntl(): Don't call dup_fd() if real_fcntl() failed.
[coloredstderr/coloredstderr.git] / src / coloredstderr.c
index 32b1dd8f106f570535f614c4b410fdcc2f7ffd7e..b2ef2975ef8d6e5ffae8625e925ae5caf46e3523 100644 (file)
@@ -49,7 +49,7 @@ static size_t (*real_fwrite)(const void *, size_t, size_t, FILE *);
 # include "debug.h"
 #endif
 
-#include "macros.h"
+#include "hookmacros.h"
 #include "trackfds.h"
 
 
@@ -280,7 +280,7 @@ int fcntl(int fd, int cmd, int arg) {
 
     result = real_fcntl(fd, cmd, arg);
     /* We only care about duping fds. */
-    if (cmd == F_DUPFD) {
+    if (cmd == F_DUPFD && result != -1) {
         int saved_errno = errno;
         dup_fd(fd, result);
         errno = saved_errno;