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 | |
| 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
| -rw-r--r-- | admin/ChangeLog | 6 | ||||
| -rwxr-xr-x | admin/merge-gnulib | 2 | ||||
| -rw-r--r-- | lib-src/ChangeLog | 15 | ||||
| -rw-r--r-- | lib-src/etags.c | 31 | ||||
| -rw-r--r-- | lib-src/hexl.c | 37 | ||||
| -rw-r--r-- | lib-src/make-docfile.c | 21 | ||||
| -rw-r--r-- | lib-src/movemail.c | 17 | ||||
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/callproc.c | 2 | ||||
| -rw-r--r-- | src/emacs.c | 20 | ||||
| -rw-r--r-- | src/minibuf.c | 23 | ||||
| -rw-r--r-- | src/sysdep.c | 19 | ||||
| -rw-r--r-- | src/systty.h | 2 | ||||
| -rw-r--r-- | src/w32.c | 4 |
14 files changed, 94 insertions, 118 deletions
diff --git a/admin/ChangeLog b/admin/ChangeLog index a20e93d38c2..90d394ca9bd 100644 --- a/admin/ChangeLog +++ b/admin/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-07-14 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Use binary-io module, O_BINARY, and "b" flag (Bug#18006). | ||
| 4 | * merge-gnulib (GNULIB_MODULES): Add binary-io. It was already | ||
| 5 | present implicitly; this just makes the dependence explicit. | ||
| 6 | |||
| 1 | 2014-06-30 Glenn Morris <rgm@gnu.org> | 7 | 2014-06-30 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * update_autogen: Find loaddefs targets rather than | 9 | * update_autogen: Find loaddefs targets rather than |
diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 5df2020f3aa..a11b6e06d27 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib | |||
| @@ -26,7 +26,7 @@ | |||
| 26 | GNULIB_URL=git://git.savannah.gnu.org/gnulib.git | 26 | GNULIB_URL=git://git.savannah.gnu.org/gnulib.git |
| 27 | 27 | ||
| 28 | GNULIB_MODULES=' | 28 | GNULIB_MODULES=' |
| 29 | alloca-opt byteswap c-ctype c-strcase | 29 | alloca-opt binary-io byteswap c-ctype c-strcase |
| 30 | careadlinkat close-stream count-one-bits count-trailing-zeros | 30 | careadlinkat close-stream count-one-bits count-trailing-zeros |
| 31 | crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 | 31 | crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 |
| 32 | dtoastr dtotimespec dup2 environ execinfo faccessat | 32 | dtoastr dtotimespec dup2 environ execinfo faccessat |
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 0e0dc51f361..e108f5b2f5d 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2014-07-14 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Use binary-io module, O_BINARY, and "b" flag (Bug#18006). | ||
| 4 | * etags.c, hexl.c, make-docfile.c: | ||
| 5 | Include binary-io.h instead of fcntl.h and/or io.h. | ||
| 6 | (main): Use set_binary_mode or SET_BINARY | ||
| 7 | in place of handcrafted code. | ||
| 8 | * etags.c (main) [DOS_NT]: | ||
| 9 | * movemail.c (main) [WINDOWSNT]: | ||
| 10 | Don't mess with _fmode. | ||
| 11 | * etags.c (main, process_file_name, analyse_regex): | ||
| 12 | Use fopen/popen's "b" flag instead. | ||
| 13 | * movemail.c (main, popmail): Use open/lk_open/mkostemp's O_BINARY | ||
| 14 | instead. | ||
| 15 | |||
| 1 | 2014-07-13 Paul Eggert <eggert@cs.ucla.edu> | 16 | 2014-07-13 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 17 | ||
| 3 | * make-docfile.c: Simplify a bit, to simplify further refactoring. | 18 | * make-docfile.c: Simplify a bit, to simplify further refactoring. |
diff --git a/lib-src/etags.c b/lib-src/etags.c index 5f1f99c4677..ae5491a8204 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c | |||
| @@ -105,17 +105,13 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; | |||
| 105 | #ifdef MSDOS | 105 | #ifdef MSDOS |
| 106 | # undef MSDOS | 106 | # undef MSDOS |
| 107 | # define MSDOS true | 107 | # define MSDOS true |
| 108 | # include <fcntl.h> | ||
| 109 | # include <sys/param.h> | 108 | # include <sys/param.h> |
| 110 | # include <io.h> | ||
| 111 | #else | 109 | #else |
| 112 | # define MSDOS false | 110 | # define MSDOS false |
| 113 | #endif /* MSDOS */ | 111 | #endif /* MSDOS */ |
| 114 | 112 | ||
| 115 | #ifdef WINDOWSNT | 113 | #ifdef WINDOWSNT |
| 116 | # include <fcntl.h> | ||
| 117 | # include <direct.h> | 114 | # include <direct.h> |
| 118 | # include <io.h> | ||
| 119 | # define MAXPATHLEN _MAX_PATH | 115 | # define MAXPATHLEN _MAX_PATH |
| 120 | # undef HAVE_NTGUI | 116 | # undef HAVE_NTGUI |
| 121 | # undef DOS_NT | 117 | # undef DOS_NT |
| @@ -131,6 +127,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; | |||
| 131 | #include <errno.h> | 127 | #include <errno.h> |
| 132 | #include <sys/types.h> | 128 | #include <sys/types.h> |
| 133 | #include <sys/stat.h> | 129 | #include <sys/stat.h> |
| 130 | #include <binary-io.h> | ||
| 134 | #include <c-strcase.h> | 131 | #include <c-strcase.h> |
| 135 | 132 | ||
| 136 | #include <assert.h> | 133 | #include <assert.h> |
| @@ -1002,13 +999,8 @@ main (int argc, char **argv) | |||
| 1002 | linebuffer filename_lb; | 999 | linebuffer filename_lb; |
| 1003 | bool help_asked = false; | 1000 | bool help_asked = false; |
| 1004 | ptrdiff_t len; | 1001 | ptrdiff_t len; |
| 1005 | char *optstring; | 1002 | char *optstring; |
| 1006 | int opt; | 1003 | int opt; |
| 1007 | |||
| 1008 | |||
| 1009 | #ifdef DOS_NT | ||
| 1010 | _fmode = O_BINARY; /* all of files are treated as binary files */ | ||
| 1011 | #endif /* DOS_NT */ | ||
| 1012 | 1004 | ||
| 1013 | progname = argv[0]; | 1005 | progname = argv[0]; |
| 1014 | nincluded_files = 0; | 1006 | nincluded_files = 0; |
| @@ -1195,15 +1187,10 @@ main (int argc, char **argv) | |||
| 1195 | if (streq (tagfile, "-")) | 1187 | if (streq (tagfile, "-")) |
| 1196 | { | 1188 | { |
| 1197 | tagf = stdout; | 1189 | tagf = stdout; |
| 1198 | #ifdef DOS_NT | 1190 | SET_BINARY (fileno (stdout)); |
| 1199 | /* Switch redirected `stdout' to binary mode (setting `_fmode' | ||
| 1200 | doesn't take effect until after `stdout' is already open). */ | ||
| 1201 | if (!isatty (fileno (stdout))) | ||
| 1202 | setmode (fileno (stdout), O_BINARY); | ||
| 1203 | #endif /* DOS_NT */ | ||
| 1204 | } | 1191 | } |
| 1205 | else | 1192 | else |
| 1206 | tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); | 1193 | tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb"); |
| 1207 | if (tagf == NULL) | 1194 | if (tagf == NULL) |
| 1208 | pfatal (tagfile); | 1195 | pfatal (tagfile); |
| 1209 | } | 1196 | } |
| @@ -1306,7 +1293,7 @@ main (int argc, char **argv) | |||
| 1306 | append_to_tagfile = true; | 1293 | append_to_tagfile = true; |
| 1307 | } | 1294 | } |
| 1308 | 1295 | ||
| 1309 | tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); | 1296 | tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb"); |
| 1310 | if (tagf == NULL) | 1297 | if (tagf == NULL) |
| 1311 | pfatal (tagfile); | 1298 | pfatal (tagfile); |
| 1312 | put_entries (nodehead); /* write all the tags (CTAGS) */ | 1299 | put_entries (nodehead); /* write all the tags (CTAGS) */ |
| @@ -1547,11 +1534,11 @@ process_file_name (char *file, language *lang) | |||
| 1547 | if (real_name == compressed_name) | 1534 | if (real_name == compressed_name) |
| 1548 | { | 1535 | { |
| 1549 | char *cmd = concat (compr->command, " ", real_name); | 1536 | char *cmd = concat (compr->command, " ", real_name); |
| 1550 | inf = (FILE *) popen (cmd, "r"); | 1537 | inf = popen (cmd, "rb"); |
| 1551 | free (cmd); | 1538 | free (cmd); |
| 1552 | } | 1539 | } |
| 1553 | else | 1540 | else |
| 1554 | inf = fopen (real_name, "r"); | 1541 | inf = fopen (real_name, "rb"); |
| 1555 | if (inf == NULL) | 1542 | if (inf == NULL) |
| 1556 | { | 1543 | { |
| 1557 | perror (real_name); | 1544 | perror (real_name); |
| @@ -5614,7 +5601,7 @@ analyse_regex (char *regex_arg) | |||
| 5614 | char *regexfile = regex_arg + 1; | 5601 | char *regexfile = regex_arg + 1; |
| 5615 | 5602 | ||
| 5616 | /* regexfile is a file containing regexps, one per line. */ | 5603 | /* regexfile is a file containing regexps, one per line. */ |
| 5617 | regexfp = fopen (regexfile, "r"); | 5604 | regexfp = fopen (regexfile, "rb"); |
| 5618 | if (regexfp == NULL) | 5605 | if (regexfp == NULL) |
| 5619 | pfatal (regexfile); | 5606 | pfatal (regexfile); |
| 5620 | linebuffer_init (®exbuf); | 5607 | linebuffer_init (®exbuf); |
diff --git a/lib-src/hexl.c b/lib-src/hexl.c index 9e21ddf9de6..51744ab08a2 100644 --- a/lib-src/hexl.c +++ b/lib-src/hexl.c | |||
| @@ -24,15 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 24 | 24 | ||
| 25 | #include <stdio.h> | 25 | #include <stdio.h> |
| 26 | #include <ctype.h> | 26 | #include <ctype.h> |
| 27 | #ifdef DOS_NT | 27 | |
| 28 | #include <fcntl.h> | 28 | #include <binary-io.h> |
| 29 | #if __DJGPP__ >= 2 | ||
| 30 | #include <io.h> | ||
| 31 | #endif | ||
| 32 | #endif | ||
| 33 | #ifdef WINDOWSNT | ||
| 34 | #include <io.h> | ||
| 35 | #endif | ||
| 36 | 29 | ||
| 37 | #define DEFAULT_GROUPING 0x01 | 30 | #define DEFAULT_GROUPING 0x01 |
| 38 | #define DEFAULT_BASE 16 | 31 | #define DEFAULT_BASE 16 |
| @@ -155,20 +148,12 @@ main (int argc, char **argv) | |||
| 155 | 148 | ||
| 156 | if (un_flag) | 149 | if (un_flag) |
| 157 | { | 150 | { |
| 158 | char buf[18]; | 151 | SET_BINARY (fileno (stdout)); |
| 159 | 152 | ||
| 160 | #ifdef DOS_NT | ||
| 161 | #if (__DJGPP__ >= 2) || (defined WINDOWSNT) | ||
| 162 | if (!isatty (fileno (stdout))) | ||
| 163 | setmode (fileno (stdout), O_BINARY); | ||
| 164 | #else | ||
| 165 | (stdout)->_flag &= ~_IOTEXT; /* print binary */ | ||
| 166 | _setmode (fileno (stdout), O_BINARY); | ||
| 167 | #endif | ||
| 168 | #endif | ||
| 169 | for (;;) | 153 | for (;;) |
| 170 | { | 154 | { |
| 171 | register int i, c = 0, d; | 155 | int i, c = 0, d; |
| 156 | char buf[18]; | ||
| 172 | 157 | ||
| 173 | #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) | 158 | #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) |
| 174 | 159 | ||
| @@ -210,15 +195,7 @@ main (int argc, char **argv) | |||
| 210 | } | 195 | } |
| 211 | else | 196 | else |
| 212 | { | 197 | { |
| 213 | #ifdef DOS_NT | 198 | SET_BINARY (fileno (fp)); |
| 214 | #if (__DJGPP__ >= 2) || (defined WINDOWSNT) | ||
| 215 | if (!isatty (fileno (fp))) | ||
| 216 | setmode (fileno (fp), O_BINARY); | ||
| 217 | #else | ||
| 218 | (fp)->_flag &= ~_IOTEXT; /* read binary */ | ||
| 219 | _setmode (fileno (fp), O_BINARY); | ||
| 220 | #endif | ||
| 221 | #endif | ||
| 222 | address = 0; | 199 | address = 0; |
| 223 | string[0] = ' '; | 200 | string[0] = ' '; |
| 224 | string[17] = '\0'; | 201 | string[17] = '\0'; |
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 6692a0a6450..cb0a56607f8 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c | |||
| @@ -38,17 +38,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 38 | 38 | ||
| 39 | #include <stdio.h> | 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> /* config.h unconditionally includes this anyway */ | 40 | #include <stdlib.h> /* config.h unconditionally includes this anyway */ |
| 41 | #ifdef MSDOS | 41 | |
| 42 | #include <fcntl.h> | ||
| 43 | #endif /* MSDOS */ | ||
| 44 | #ifdef WINDOWSNT | 42 | #ifdef WINDOWSNT |
| 45 | /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this | 43 | /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this |
| 46 | is really just insurance. */ | 44 | is really just insurance. */ |
| 47 | #undef fopen | 45 | #undef fopen |
| 48 | #include <fcntl.h> | ||
| 49 | #include <direct.h> | 46 | #include <direct.h> |
| 50 | #endif /* WINDOWSNT */ | 47 | #endif /* WINDOWSNT */ |
| 51 | 48 | ||
| 49 | #include <binary-io.h> | ||
| 50 | |||
| 52 | #ifdef DOS_NT | 51 | #ifdef DOS_NT |
| 53 | /* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this | 52 | /* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this |
| 54 | is really just insurance. | 53 | is really just insurance. |
| @@ -167,19 +166,7 @@ main (int argc, char **argv) | |||
| 167 | ++i; | 166 | ++i; |
| 168 | } | 167 | } |
| 169 | 168 | ||
| 170 | /* Don't put CRs in the output file. */ | 169 | set_binary_mode (fileno (stdout), O_BINARY); |
| 171 | #ifdef MSDOS | ||
| 172 | _fmode = O_BINARY; | ||
| 173 | #if 0 /* Suspicion is that this causes hanging. | ||
| 174 | So instead we require people to use -o on MSDOS. */ | ||
| 175 | (stdout)->_flag &= ~_IOTEXT; | ||
| 176 | _setmode (fileno (stdout), O_BINARY); | ||
| 177 | #endif | ||
| 178 | #endif /* MSDOS */ | ||
| 179 | #ifdef WINDOWSNT | ||
| 180 | _fmode = O_BINARY; | ||
| 181 | _setmode (fileno (stdout), O_BINARY); | ||
| 182 | #endif /* WINDOWSNT */ | ||
| 183 | 170 | ||
| 184 | if (generate_globals) | 171 | if (generate_globals) |
| 185 | start_globals (); | 172 | start_globals (); |
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index d0d00fcf4cc..c600fc0ea53 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -191,11 +191,6 @@ main (int argc, char **argv) | |||
| 191 | uid_t real_gid = getgid (); | 191 | uid_t real_gid = getgid (); |
| 192 | uid_t priv_gid = getegid (); | 192 | uid_t priv_gid = getegid (); |
| 193 | 193 | ||
| 194 | #ifdef WINDOWSNT | ||
| 195 | /* Ensure all file i/o is in binary mode. */ | ||
| 196 | _fmode = _O_BINARY; | ||
| 197 | #endif | ||
| 198 | |||
| 199 | delete_lockname = 0; | 194 | delete_lockname = 0; |
| 200 | 195 | ||
| 201 | while ((c = getopt (argc, argv, ARGSTR)) != EOF) | 196 | while ((c = getopt (argc, argv, ARGSTR)) != EOF) |
| @@ -304,7 +299,7 @@ main (int argc, char **argv) | |||
| 304 | 299 | ||
| 305 | memcpy (tempname, inname, inname_dirlen); | 300 | memcpy (tempname, inname, inname_dirlen); |
| 306 | strcpy (tempname + inname_dirlen, "EXXXXXX"); | 301 | strcpy (tempname + inname_dirlen, "EXXXXXX"); |
| 307 | desc = mkostemp (tempname, 0); | 302 | desc = mkostemp (tempname, O_BINARY); |
| 308 | if (desc < 0) | 303 | if (desc < 0) |
| 309 | { | 304 | { |
| 310 | int mkostemp_errno = errno; | 305 | int mkostemp_errno = errno; |
| @@ -358,12 +353,12 @@ main (int argc, char **argv) | |||
| 358 | 353 | ||
| 359 | #ifndef MAIL_USE_MMDF | 354 | #ifndef MAIL_USE_MMDF |
| 360 | #ifdef MAIL_USE_SYSTEM_LOCK | 355 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 361 | indesc = open (inname, O_RDWR); | 356 | indesc = open (inname, O_RDWR | O_BINARY); |
| 362 | #else /* if not MAIL_USE_SYSTEM_LOCK */ | 357 | #else /* if not MAIL_USE_SYSTEM_LOCK */ |
| 363 | indesc = open (inname, O_RDONLY); | 358 | indesc = open (inname, O_RDONLY | O_BINARY); |
| 364 | #endif /* not MAIL_USE_SYSTEM_LOCK */ | 359 | #endif /* not MAIL_USE_SYSTEM_LOCK */ |
| 365 | #else /* MAIL_USE_MMDF */ | 360 | #else /* MAIL_USE_MMDF */ |
| 366 | indesc = lk_open (inname, O_RDONLY, 0, 0, 10); | 361 | indesc = lk_open (inname, O_RDONLY | O_BINARY, 0, 0, 10); |
| 367 | #endif /* MAIL_USE_MMDF */ | 362 | #endif /* MAIL_USE_MMDF */ |
| 368 | 363 | ||
| 369 | if (indesc < 0) | 364 | if (indesc < 0) |
| @@ -372,7 +367,7 @@ main (int argc, char **argv) | |||
| 372 | /* Make sure the user can read the output file. */ | 367 | /* Make sure the user can read the output file. */ |
| 373 | umask (umask (0) & 0377); | 368 | umask (umask (0) & 0377); |
| 374 | 369 | ||
| 375 | outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666); | 370 | outdesc = open (outname, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0666); |
| 376 | if (outdesc < 0) | 371 | if (outdesc < 0) |
| 377 | pfatal_with_name (outname); | 372 | pfatal_with_name (outname); |
| 378 | 373 | ||
| @@ -675,7 +670,7 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse | |||
| 675 | return EXIT_SUCCESS; | 670 | return EXIT_SUCCESS; |
| 676 | } | 671 | } |
| 677 | 672 | ||
| 678 | mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); | 673 | mbfi = open (outfile, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0666); |
| 679 | if (mbfi < 0) | 674 | if (mbfi < 0) |
| 680 | { | 675 | { |
| 681 | pop_close (server); | 676 | pop_close (server); |
diff --git a/src/ChangeLog b/src/ChangeLog index 53795742131..ee600602895 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,18 @@ | |||
| 1 | 2014-07-14 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2014-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. |
| 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); |
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 */ |
| 83 | extern void emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE; | 83 | extern int emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE; |
| 84 | extern int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE; | 84 | extern int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE; |
| 85 | extern void suppress_echo_on_tty (int); | 85 | extern void suppress_echo_on_tty (int); |
| 86 | extern int serial_open (Lisp_Object); | 86 | extern int serial_open (Lisp_Object); |
| @@ -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 |