diff options
| author | Paul Eggert | 2014-07-14 12:23:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-07-14 12:23:18 -0700 |
| commit | ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3 (patch) | |
| tree | 5ef95ac07de2a856369957a7ac047b9f58b78594 /src/sysdep.c | |
| parent | 091adafaac52ff409790728af63cab19bd52fc8f (diff) | |
| download | emacs-ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3.tar.gz emacs-ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3.zip | |
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
Diffstat (limited to 'src/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 19 |
1 files changed, 12 insertions, 7 deletions
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) | |||
| 775 | /* Getting and setting emacs_tty structures. */ | 775 | /* Getting and setting emacs_tty structures. */ |
| 776 | 776 | ||
| 777 | /* Set *TC to the parameters associated with the terminal FD, | 777 | /* Set *TC to the parameters associated with the terminal FD, |
| 778 | or clear it if the parameters are not available. */ | 778 | or clear it if the parameters are not available. |
| 779 | void | 779 | Return 0 on success, -1 on failure. */ |
| 780 | int | ||
| 780 | emacs_get_tty (int fd, struct emacs_tty *settings) | 781 | emacs_get_tty (int fd, struct emacs_tty *settings) |
| 781 | { | 782 | { |
| 782 | /* Retrieve the primary parameters - baud rate, character size, etcetera. */ | 783 | /* Retrieve the primary parameters - baud rate, character size, etcetera. */ |
| @@ -786,15 +787,16 @@ emacs_get_tty (int fd, struct emacs_tty *settings) | |||
| 786 | HANDLE h = (HANDLE)_get_osfhandle (fd); | 787 | HANDLE h = (HANDLE)_get_osfhandle (fd); |
| 787 | DWORD console_mode; | 788 | DWORD console_mode; |
| 788 | 789 | ||
| 789 | if (h && h != INVALID_HANDLE_VALUE) | 790 | if (h && h != INVALID_HANDLE_VALUE && GetConsoleMode (h, &console_mode)) |
| 790 | { | 791 | { |
| 791 | if (GetConsoleMode (h, &console_mode)) | 792 | settings->main = console_mode; |
| 792 | settings->main = console_mode; | 793 | return 0; |
| 793 | } | 794 | } |
| 794 | #endif /* WINDOWSNT */ | 795 | #endif /* WINDOWSNT */ |
| 796 | return -1; | ||
| 795 | #else /* !DOS_NT */ | 797 | #else /* !DOS_NT */ |
| 796 | /* We have those nifty POSIX tcmumbleattr functions. */ | 798 | /* We have those nifty POSIX tcmumbleattr functions. */ |
| 797 | tcgetattr (fd, &settings->main); | 799 | return tcgetattr (fd, &settings->main); |
| 798 | #endif | 800 | #endif |
| 799 | } | 801 | } |
| 800 | 802 | ||
| @@ -2198,6 +2200,7 @@ emacs_abort (void) | |||
| 2198 | #endif | 2200 | #endif |
| 2199 | 2201 | ||
| 2200 | /* Open FILE for Emacs use, using open flags OFLAG and mode MODE. | 2202 | /* Open FILE for Emacs use, using open flags OFLAG and mode MODE. |
| 2203 | Use binary I/O on systems that care about text vs binary I/O. | ||
| 2201 | Arrange for subprograms to not inherit the file descriptor. | 2204 | Arrange for subprograms to not inherit the file descriptor. |
| 2202 | Prefer a method that is multithread-safe, if available. | 2205 | Prefer a method that is multithread-safe, if available. |
| 2203 | Do not fail merely because the open was interrupted by a signal. | 2206 | Do not fail merely because the open was interrupted by a signal. |
| @@ -2207,6 +2210,8 @@ int | |||
| 2207 | emacs_open (const char *file, int oflags, int mode) | 2210 | emacs_open (const char *file, int oflags, int mode) |
| 2208 | { | 2211 | { |
| 2209 | int fd; | 2212 | int fd; |
| 2213 | if (! (oflags & O_TEXT)) | ||
| 2214 | oflags |= O_BINARY; | ||
| 2210 | oflags |= O_CLOEXEC; | 2215 | oflags |= O_CLOEXEC; |
| 2211 | while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR) | 2216 | while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR) |
| 2212 | QUIT; | 2217 | QUIT; |
| @@ -2254,7 +2259,7 @@ emacs_pipe (int fd[2]) | |||
| 2254 | #ifdef MSDOS | 2259 | #ifdef MSDOS |
| 2255 | return pipe (fd); | 2260 | return pipe (fd); |
| 2256 | #else /* !MSDOS */ | 2261 | #else /* !MSDOS */ |
| 2257 | int result = pipe2 (fd, O_CLOEXEC); | 2262 | int result = pipe2 (fd, O_BINARY | O_CLOEXEC); |
| 2258 | if (! O_CLOEXEC && result == 0) | 2263 | if (! O_CLOEXEC && result == 0) |
| 2259 | { | 2264 | { |
| 2260 | fcntl (fd[0], F_SETFD, FD_CLOEXEC); | 2265 | fcntl (fd[0], F_SETFD, FD_CLOEXEC); |