Commit 0322457e authored by Paul Eggert's avatar Paul Eggert
Browse files

Port redirect-debugging-output to MS-Windows

Suggested by Eli Zaretskii in:
http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00037.html
* src/print.c [WINDOWSNT]: Include sys/socket.h.
* src/w32.c (sys_dup2): Work around problem with MS-Windows _dup2.
parent 6bccb19c
......@@ -38,6 +38,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <float.h>
#include <ftoastr.h>
#ifdef WINDOWSNT
# include <sys/socket.h> /* for F_DUPFD_CLOEXEC */
#endif
struct terminal;
/* Avoid actual stack overflow in print. */
......
......@@ -8181,17 +8181,33 @@ sys_dup2 (int src, int dst)
return -1;
}
/* make sure we close the destination first if it's a pipe or socket */
if (src != dst && fd_info[dst].flags != 0)
/* MS _dup2 seems to have weird side effect when invoked with 2
identical arguments: an attempt to fclose the corresponding stdio
stream after that hangs (we do close standard streams in
init_ntproc). Attempt to avoid that by not calling _dup2 that
way: if SRC is valid, we know that dup2 should be a no-op, so do
nothing and return DST. */
if (src == dst)
{
if ((HANDLE)_get_osfhandle (src) == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return -1;
}
return dst;
}
/* Make sure we close the destination first if it's a pipe or socket. */
if (fd_info[dst].flags != 0)
sys_close (dst);
rc = _dup2 (src, dst);
if (rc == 0)
{
/* duplicate our internal info as well */
/* Duplicate our internal info as well. */
fd_info[dst] = fd_info[src];
}
return rc;
return rc == 0 ? dst : rc;
}
int
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment