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 /lib-src | |
| 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 'lib-src')
| -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 |
5 files changed, 41 insertions, 80 deletions
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); |