From ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 14 Jul 2014 12:23:18 -0700 Subject: Use binary-io module, O_BINARY, and "b" flag. * admin/merge-gnulib (GNULIB_MODULES): Add binary-io. It was already present implicitly; this just makes the dependence explicit. * lib-src/etags.c, lib-src/hexl.c, lib-src/make-docfile.c: Include binary-io.h instead of fcntl.h and/or io.h. (main): Use set_binary_mode or SET_BINARY in place of handcrafted code. * lib-src/etags.c (main) [DOS_NT]: * lib-src/movemail.c (main) [WINDOWSNT]: Don't mess with _fmode. * lib-src/etags.c (main, process_file_name, analyse_regex): Use fopen/popen's "b" flag instead. * lib-src/movemail.c (main, popmail): Use open/lk_open/mkostemp's O_BINARY instead. * src/callproc.c (create_temp_file): Use mkostemp's O_BINARY flag. * src/emacs.c [MSDOS]: * src/emacs.c (main) [DOS_NT]: Don't mess with _fmode. (main) [MSDOS]: Use SET_BINARY instead of setmode. * src/minibuf.c: Include binary-io.h instead of fcntl.h. (read_minibuf_noninteractive): Use set_binary_mode instead of handcrafted code. Don't call emacs_set_tty if emacs_get_tty failed. * src/sysdep.c, src/systty.h (emacs_get_tty): Return int, not void. * src/sysdep.c (emacs_open, emacs_pipe): Use O_BINARY. * src/w32.c (pipe2): Adjust eassert to include O_BINARY. Fixes: debbugs:18006 --- src/sysdep.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/sysdep.c') diff --git a/src/sysdep.c b/src/sysdep.c index eae15ea1ec3..d5cfd5b88cf 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -775,8 +775,9 @@ widen_foreground_group (int fd) /* Getting and setting emacs_tty structures. */ /* Set *TC to the parameters associated with the terminal FD, - or clear it if the parameters are not available. */ -void + or clear it if the parameters are not available. + Return 0 on success, -1 on failure. */ +int emacs_get_tty (int fd, struct emacs_tty *settings) { /* Retrieve the primary parameters - baud rate, character size, etcetera. */ @@ -786,15 +787,16 @@ emacs_get_tty (int fd, struct emacs_tty *settings) HANDLE h = (HANDLE)_get_osfhandle (fd); DWORD console_mode; - if (h && h != INVALID_HANDLE_VALUE) + if (h && h != INVALID_HANDLE_VALUE && GetConsoleMode (h, &console_mode)) { - if (GetConsoleMode (h, &console_mode)) - settings->main = console_mode; + settings->main = console_mode; + return 0; } #endif /* WINDOWSNT */ + return -1; #else /* !DOS_NT */ /* We have those nifty POSIX tcmumbleattr functions. */ - tcgetattr (fd, &settings->main); + return tcgetattr (fd, &settings->main); #endif } @@ -2198,6 +2200,7 @@ emacs_abort (void) #endif /* Open FILE for Emacs use, using open flags OFLAG and mode MODE. + Use binary I/O on systems that care about text vs binary I/O. Arrange for subprograms to not inherit the file descriptor. Prefer a method that is multithread-safe, if available. Do not fail merely because the open was interrupted by a signal. @@ -2207,6 +2210,8 @@ int emacs_open (const char *file, int oflags, int mode) { int fd; + if (! (oflags & O_TEXT)) + oflags |= O_BINARY; oflags |= O_CLOEXEC; while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR) QUIT; @@ -2254,7 +2259,7 @@ emacs_pipe (int fd[2]) #ifdef MSDOS return pipe (fd); #else /* !MSDOS */ - int result = pipe2 (fd, O_CLOEXEC); + int result = pipe2 (fd, O_BINARY | O_CLOEXEC); if (! O_CLOEXEC && result == 0) { fcntl (fd[0], F_SETFD, FD_CLOEXEC); -- cgit v1.2.1