[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#18006: Simplify via set_binary_mode
From: |
Paul Eggert |
Subject: |
bug#18006: Simplify via set_binary_mode |
Date: |
Sat, 12 Jul 2014 22:28:56 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
Eli Zaretskii wrote:
. in some places, we want all file I/O to be in binary mode; Gnulib
doesn't support that
The Emacs code can continue to use _fmode as before; that part won't be
simplified, but one step at a time.
. some of the code needs to switch a file descriptor to binary or
text mode only when the descriptor is or isn't connected to a
terminal device; Gnulib is ambivalent about that (it always does
that for MSDOS, and never for Windows)
binary-io has two interfaces; one (set_binary_mode) always does it, on
all platforms; the other (SET_BINARY) deliberately has no effect on
__DJGPP__ when isatty returns nonzero. Emacs can use either interface,
as it needs. Should SET_BINARY also should have no effect on MS-Windows
when isatty returns nonzero? If so, I suppose we can change SET_BINARY
to do that.
. AFAIK, Gnulib's binary-io also replaces isatty
It doesn't, so this shouldn't be a problem. (Emacs already uses
binary-io, by the way; if this were a problem I expect we'd already have
run into it.)
. we don't want in Emacs the msvc-nothrow wrappers for library
functions
binary-io doesn't do that either.
/* Don't put CRs in the DOC file. */
-#ifdef MSDOS
- _fmode = O_BINARY;
-#if 0 /* Suspicion is that this causes hanging.
- So instead we require people to use -o on MSDOS. */
- (stdout)->_flag &= ~_IOTEXT;
- _setmode (fileno (stdout), O_BINARY);
-#endif
- outfile = 0;
-#endif /* MSDOS */
-#ifdef WINDOWSNT
- _fmode = O_BINARY;
- _setmode (fileno (stdout), O_BINARY);
-#endif /* WINDOWSNT */
+ set_binary_mode (fileno (stdout), O_BINARY);
This is wrong: setting _fmode affects all I/O, input and output, not
just stdout. Gnulib's binary-io doesn't have the equivalent
functionality.
If setting _fmode affects all I/O, why does the WINDOWSNT code bother to
call _setmode? Conversely, why does make-docfile.c need to set _fmode,
if the intent is "Don't put CRs in the DOC file"; shouldn't it suffice
to call _setmode on stdout?
This logic is flawed: if emacs_get_tty failed, then emacs_set_tty
should not be called as well.
I was just copying the existing logic. But it's easy to fix while we're
at it; revised patch attached.
This will not work with Windows isatty, because it doesn't return 1
when fd is connected to a console.
Thanks, I also tried to address that in the attached patch.
binary-io.patch
Description: Text document
- bug#18006: Simplify via set_binary_mode, Paul Eggert, 2014/07/12
- bug#18006: Simplify via set_binary_mode, Eli Zaretskii, 2014/07/13
- bug#18006: Simplify via set_binary_mode,
Paul Eggert <=
- bug#18006: Simplify via set_binary_mode, Eli Zaretskii, 2014/07/13
- bug#18006: Simplify via set_binary_mode, Paul Eggert, 2014/07/13
- bug#18006: Simplify via set_binary_mode, Eli Zaretskii, 2014/07/14
- bug#18006: Simplify via set_binary_mode, Paul Eggert, 2014/07/14
- bug#18006: Simplify via set_binary_mode, Eli Zaretskii, 2014/07/15
- bug#18006: Simplify via set_binary_mode, Paul Eggert, 2014/07/15