Re: [PATCH 3/3] Set stdin/stdout/stderr to binary mode in cygwin.

Yao Qi
2013-08-01T08:10:28Z

On 07/29/2013 11:44 PM, Eli Zaretskii wrote:
>> + setmode (fileno (stdin), O_BINARY);
>> >+ setmode (fileno (stdout), O_BINARY);
>> >+ setmode (fileno (stderr), O_BINARY);
> Do you really need all 3 of the standard handles in binary mode? I
> thought the problem was only with output?

Setting stdin in binary mode is for another purpose, should go to a
separated patch. Sorry for the confusion. Patch below is to only set
stdout and stderr in binary mode.

--
Yao (é½å°§)

gdb:

2013-08-01 Pedro Alves <pedro@codesourcery.com>
Daniel Jacobowitz <dan@codesourcery.com>
Yao Qi <yao@codesourcery.com>

* main.c [__MINGW32__]: Include fcntl.h and windows.h.
(captured_main) [__MINGW32__]: Set stdout and stderr to
binary mode if GDB is using cygwin pty.
---
gdb/main.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index 3a2fee6..6a79df9 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -47,6 +47,11 @@
#include "filenames.h"
#include "filestuff.h"

+#ifdef __MINGW32__
+#include <fcntl.h>
+#include <windows.h>
+#endif
+
/* The selected interpreter. This will be used as a set command
variable, so it should always be malloc'ed - since
do_setshow_command will free it. */
@@ -384,6 +389,13 @@ captured_main (void *data)
other operation is performed. */
setvbuf (stdout, NULL, _IONBF, BUFSIZ);
setvbuf (stderr, NULL, _IONBF, BUFSIZ);
+
+ /* In textmode, a '\n' is automatically expanded into "\r\n". This
+ results in expect seeing "\r\r\n". The tests aren't prepared
+ currently for other forms of eol. As a workaround, we force the
+ output to binary mode. */
+ setmode (fileno (stdout), O_BINARY);
+ setmode (fileno (stderr), O_BINARY);
}
#endif

--
1.7.7.6