diff options
| author | Paul Eggert | 2016-04-04 09:42:58 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-04-04 09:44:19 -0700 |
| commit | 0322457e2bec0b9409a03887a8235dbe14e357f4 (patch) | |
| tree | ef9d146e3f1ea2e33c84283565cecd832a885d52 /src | |
| parent | 6bccb19c9bef1189c8e853ff7cc16b889a3a57e3 (diff) | |
| download | emacs-0322457e2bec0b9409a03887a8235dbe14e357f4.tar.gz emacs-0322457e2bec0b9409a03887a8235dbe14e357f4.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 4 | ||||
| -rw-r--r-- | src/w32.c | 24 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/print.c b/src/print.c index db2918ff478..83edbb6bfa4 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -38,6 +38,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 38 | #include <float.h> | 38 | #include <float.h> |
| 39 | #include <ftoastr.h> | 39 | #include <ftoastr.h> |
| 40 | 40 | ||
| 41 | #ifdef WINDOWSNT | ||
| 42 | # include <sys/socket.h> /* for F_DUPFD_CLOEXEC */ | ||
| 43 | #endif | ||
| 44 | |||
| 41 | struct terminal; | 45 | struct terminal; |
| 42 | 46 | ||
| 43 | /* Avoid actual stack overflow in print. */ | 47 | /* Avoid actual stack overflow in print. */ |
| @@ -8181,17 +8181,33 @@ sys_dup2 (int src, int dst) | |||
| 8181 | return -1; | 8181 | return -1; |
| 8182 | } | 8182 | } |
| 8183 | 8183 | ||
| 8184 | /* make sure we close the destination first if it's a pipe or socket */ | 8184 | /* MS _dup2 seems to have weird side effect when invoked with 2 |
| 8185 | if (src != dst && fd_info[dst].flags != 0) | 8185 | identical arguments: an attempt to fclose the corresponding stdio |
| 8186 | stream after that hangs (we do close standard streams in | ||
| 8187 | init_ntproc). Attempt to avoid that by not calling _dup2 that | ||
| 8188 | way: if SRC is valid, we know that dup2 should be a no-op, so do | ||
| 8189 | nothing and return DST. */ | ||
| 8190 | if (src == dst) | ||
| 8191 | { | ||
| 8192 | if ((HANDLE)_get_osfhandle (src) == INVALID_HANDLE_VALUE) | ||
| 8193 | { | ||
| 8194 | errno = EBADF; | ||
| 8195 | return -1; | ||
| 8196 | } | ||
| 8197 | return dst; | ||
| 8198 | } | ||
| 8199 | |||
| 8200 | /* Make sure we close the destination first if it's a pipe or socket. */ | ||
| 8201 | if (fd_info[dst].flags != 0) | ||
| 8186 | sys_close (dst); | 8202 | sys_close (dst); |
| 8187 | 8203 | ||
| 8188 | rc = _dup2 (src, dst); | 8204 | rc = _dup2 (src, dst); |
| 8189 | if (rc == 0) | 8205 | if (rc == 0) |
| 8190 | { | 8206 | { |
| 8191 | /* duplicate our internal info as well */ | 8207 | /* Duplicate our internal info as well. */ |
| 8192 | fd_info[dst] = fd_info[src]; | 8208 | fd_info[dst] = fd_info[src]; |
| 8193 | } | 8209 | } |
| 8194 | return rc; | 8210 | return rc == 0 ? dst : rc; |
| 8195 | } | 8211 | } |
| 8196 | 8212 | ||
| 8197 | int | 8213 | int |