unlink: new module, for Solaris 9 bug
[gnulib.git] / lib / dup3.c
index f730e81..879a907 100644 (file)
@@ -63,6 +63,10 @@ dup3 (int oldfd, int newfd, int flags)
        if (!(result < 0 && errno == ENOSYS))
          {
            have_dup3_really = 1;
+#if REPLACE_FCHDIR
+           if (0 <= result)
+             result = _gl_register_dup (oldfd, newfd);
+#endif
            return result;
          }
        have_dup3_really = -1;
@@ -180,6 +184,10 @@ dup3 (int oldfd, int newfd, int flags)
        errno = saved_errno;
       }
 
+#if REPLACE_FCHDIR
+      if (result == newfd)
+       result = _gl_register_dup (oldfd, newfd);
+#endif
       return result;
     }
 
@@ -218,5 +226,8 @@ dup3 (int oldfd, int newfd, int flags)
     setmode (newfd, O_TEXT);
 #endif
 
+#if REPLACE_FCHDIR
+  newfd = _gl_register_dup (oldfd, newfd);
+#endif
   return newfd;
 }