NEWS.stable: log cherry-pick [d1fa59e]->[e238a25] strtoimax, strtoumax: Document...
[gnulib.git] / lib / dup2.c
index a4422bf..e00dc7b 100644 (file)
@@ -1,6 +1,6 @@
 /* Duplicate an open file descriptor to a specified file descriptor.
 
-   Copyright (C) 1999, 2004-2007, 2009-2010 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2004-2007, 2009-2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -59,6 +59,10 @@ rpl_dup2 (int fd, int desired_fd)
       errno = EBADF;
       return -1;
     }
+# elif !defined __linux__
+  /* On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
+  if (fd == desired_fd)
+    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
 # endif
   result = dup2 (fd, desired_fd);
 # ifdef __linux__