aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2014-07-14 12:23:18 -0700
committerPaul Eggert2014-07-14 12:23:18 -0700
commitba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3 (patch)
tree5ef95ac07de2a856369957a7ac047b9f58b78594 /src
parent091adafaac52ff409790728af63cab19bd52fc8f (diff)
downloademacs-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')
-rw-r--r--src/ChangeLog13
-rw-r--r--src/callproc.c2
-rw-r--r--src/emacs.c20
-rw-r--r--src/minibuf.c23
-rw-r--r--src/sysdep.c19
-rw-r--r--src/systty.h2
-rw-r--r--src/w32.c4
7 files changed, 46 insertions, 37 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 53795742131..ee600602895 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,18 @@
12014-07-14 Paul Eggert <eggert@cs.ucla.edu> 12014-07-14 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Use binary-io module, O_BINARY, and "b" flag (Bug#18006).
4 * callproc.c (create_temp_file): Use mkostemp's O_BINARY flag.
5 * emacs.c [MSDOS]:
6 * emacs.c (main) [DOS_NT]: Don't mess with _fmode.
7 (main) [MSDOS]: Use SET_BINARY instead of setmode.
8 * minibuf.c: Include binary-io.h instead of fcntl.h.
9 (read_minibuf_noninteractive):
10 Use set_binary_mode instead of handcrafted code.
11 Don't call emacs_set_tty if emacs_get_tty failed.
12 * sysdep.c, systty.h (emacs_get_tty): Return int, not void.
13 * sysdep.c (emacs_open, emacs_pipe): Use O_BINARY.
14 * w32.c (pipe2): Adjust eassert to include O_BINARY.
15
3 * macros.c (Fstart_kbd_macro): Avoid need for overflow check. 16 * macros.c (Fstart_kbd_macro): Avoid need for overflow check.
4 This works around a GCC compiler bug when Emacs is configured with 17 This works around a GCC compiler bug when Emacs is configured with
5 --enable-gcc-warnings. 18 --enable-gcc-warnings.
diff --git a/src/callproc.c b/src/callproc.c
index 9fbc7e5b713..2f68ea6f328 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -982,7 +982,7 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args,
982 982
983 count = SPECPDL_INDEX (); 983 count = SPECPDL_INDEX ();
984 record_unwind_protect_nothing (); 984 record_unwind_protect_nothing ();
985 fd = mkostemp (tempfile, O_CLOEXEC); 985 fd = mkostemp (tempfile, O_BINARY | O_CLOEXEC);
986 if (fd < 0) 986 if (fd < 0)
987 report_file_error ("Failed to open temporary file using pattern", 987 report_file_error ("Failed to open temporary file using pattern",
988 pattern); 988 pattern);
diff --git a/src/emacs.c b/src/emacs.c
index 117ce4decdb..a53b4cfd4ed 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -51,6 +51,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#include "cygw32.h" 51#include "cygw32.h"
52#endif 52#endif
53 53
54#ifdef MSDOS
55#include <binary-io.h>
56#endif
57
54#ifdef HAVE_WINDOW_SYSTEM 58#ifdef HAVE_WINDOW_SYSTEM
55#include TERM_HEADER 59#include TERM_HEADER
56#endif /* HAVE_WINDOW_SYSTEM */ 60#endif /* HAVE_WINDOW_SYSTEM */
@@ -918,20 +922,10 @@ main (int argc, char **argv)
918 922
919#endif /* not SYSTEM_MALLOC */ 923#endif /* not SYSTEM_MALLOC */
920 924
921#if defined (MSDOS) || defined (WINDOWSNT)
922 /* We do all file input/output as binary files. When we need to translate
923 newlines, we do that manually. */
924 _fmode = O_BINARY;
925#endif /* MSDOS || WINDOWSNT */
926
927#ifdef MSDOS 925#ifdef MSDOS
928 if (!isatty (fileno (stdin))) 926 SET_BINARY (fileno (stdin));
929 setmode (fileno (stdin), O_BINARY); 927 fflush (stdout);
930 if (!isatty (fileno (stdout))) 928 SET_BINARY (fileno (stdout));
931 {
932 fflush (stdout);
933 setmode (fileno (stdout), O_BINARY);
934 }
935#endif /* MSDOS */ 929#endif /* MSDOS */
936 930
937 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case. 931 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.
diff --git a/src/minibuf.c b/src/minibuf.c
index e2450b53964..b85d3f57df3 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -22,9 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#include <errno.h> 22#include <errno.h>
23#include <stdio.h> 23#include <stdio.h>
24 24
25#ifdef WINDOWSNT 25#include <binary-io.h>
26#include <fcntl.h> /* For O_BINARY, O_TEXT. */
27#endif
28 26
29#include "lisp.h" 27#include "lisp.h"
30#include "commands.h" 28#include "commands.h"
@@ -231,6 +229,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
231 int c; 229 int c;
232 unsigned char hide_char = 0; 230 unsigned char hide_char = 0;
233 struct emacs_tty etty; 231 struct emacs_tty etty;
232 bool etty_valid;
234 233
235 /* Check, whether we need to suppress echoing. */ 234 /* Check, whether we need to suppress echoing. */
236 if (CHARACTERP (Vread_hide_char)) 235 if (CHARACTERP (Vread_hide_char))
@@ -239,11 +238,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
239 /* Manipulate tty. */ 238 /* Manipulate tty. */
240 if (hide_char) 239 if (hide_char)
241 { 240 {
242 emacs_get_tty (fileno (stdin), &etty); 241 etty_valid = emacs_get_tty (fileno (stdin), &etty) == 0;
243#ifdef WINDOWSNT 242 if (etty_valid)
244 if (isatty (fileno (stdin))) 243 set_binary_mode (fileno (stdin), O_BINARY);
245 _setmode (fileno (stdin), O_BINARY);
246#endif
247 suppress_echo_on_tty (fileno (stdin)); 244 suppress_echo_on_tty (fileno (stdin));
248 } 245 }
249 246
@@ -281,11 +278,11 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
281 if (hide_char) 278 if (hide_char)
282 { 279 {
283 fprintf (stdout, "\n"); 280 fprintf (stdout, "\n");
284 emacs_set_tty (fileno (stdin), &etty, 0); 281 if (etty_valid)
285#ifdef WINDOWSNT 282 {
286 if (isatty (fileno (stdin))) 283 emacs_set_tty (fileno (stdin), &etty, 0);
287 _setmode (fileno (stdin), O_TEXT); 284 set_binary_mode (fileno (stdin), O_TEXT);
288#endif 285 }
289 } 286 }
290 287
291 if (len || c == '\n' || c == '\r') 288 if (len || c == '\n' || c == '\r')
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.
779void 779 Return 0 on success, -1 on failure. */
780int
780emacs_get_tty (int fd, struct emacs_tty *settings) 781emacs_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
2207emacs_open (const char *file, int oflags, int mode) 2210emacs_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);
diff --git a/src/systty.h b/src/systty.h
index dcab0268393..a29c4933d7b 100644
--- a/src/systty.h
+++ b/src/systty.h
@@ -80,7 +80,7 @@ struct emacs_tty {
80}; 80};
81 81
82/* From sysdep.c or w32.c */ 82/* From sysdep.c or w32.c */
83extern void emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE; 83extern int emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE;
84extern int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE; 84extern int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE;
85extern void suppress_echo_on_tty (int); 85extern void suppress_echo_on_tty (int);
86extern int serial_open (Lisp_Object); 86extern int serial_open (Lisp_Object);
diff --git a/src/w32.c b/src/w32.c
index 37a01a311a6..7cb9d8960c5 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -882,7 +882,7 @@ set_named_security_info (LPCTSTR lpObjectName,
882 g_b_init_set_named_security_info_a = 1; 882 g_b_init_set_named_security_info_a = 1;
883 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 883 hm_advapi32 = LoadLibrary ("Advapi32.dll");
884 s_pfn_Set_Named_Security_InfoA = 884 s_pfn_Set_Named_Security_InfoA =
885 (SetNamedSecurityInfoA_Proc) GetProcAddress (hm_advapi32, 885 (SetNamedSecurityInfoA_Proc) GetProcAddress (hm_advapi32,
886 "SetNamedSecurityInfoA"); 886 "SetNamedSecurityInfoA");
887 } 887 }
888 if (s_pfn_Set_Named_Security_InfoA == NULL) 888 if (s_pfn_Set_Named_Security_InfoA == NULL)
@@ -7865,7 +7865,7 @@ pipe2 (int * phandles, int pipe2_flags)
7865 int rc; 7865 int rc;
7866 unsigned flags; 7866 unsigned flags;
7867 7867
7868 eassert (pipe2_flags == O_CLOEXEC); 7868 eassert (pipe2_flags == (O_BINARY | O_CLOEXEC));
7869 7869
7870 /* make pipe handles non-inheritable; when we spawn a child, we 7870 /* make pipe handles non-inheritable; when we spawn a child, we
7871 replace the relevant handle with an inheritable one. Also put 7871 replace the relevant handle with an inheritable one. Also put