summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-07-14 12:23:18 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-07-14 12:23:18 -0700
commitba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3 (patch)
tree5ef95ac07de2a856369957a7ac047b9f58b78594 /lib-src
parent091adafaac52ff409790728af63cab19bd52fc8f (diff)
downloademacs-ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3.tar.gz
emacs-ba1ed52f0c2c7fd15fe1feadabfd0af88e19b4c3.tar.bz2
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/ChangeLog15
-rw-r--r--lib-src/etags.c31
-rw-r--r--lib-src/hexl.c37
-rw-r--r--lib-src/make-docfile.c21
-rw-r--r--lib-src/movemail.c17
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 @@
+2014-07-14 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use binary-io module, O_BINARY, and "b" flag (Bug#18006).
+ * etags.c, hexl.c, 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.
+ * etags.c (main) [DOS_NT]:
+ * movemail.c (main) [WINDOWSNT]:
+ Don't mess with _fmode.
+ * etags.c (main, process_file_name, analyse_regex):
+ Use fopen/popen's "b" flag instead.
+ * movemail.c (main, popmail): Use open/lk_open/mkostemp's O_BINARY
+ instead.
+
2014-07-13 Paul Eggert <eggert@cs.ucla.edu>
* 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";
#ifdef MSDOS
# undef MSDOS
# define MSDOS true
-# include <fcntl.h>
# include <sys/param.h>
-# include <io.h>
#else
# define MSDOS false
#endif /* MSDOS */
#ifdef WINDOWSNT
-# include <fcntl.h>
# include <direct.h>
-# include <io.h>
# define MAXPATHLEN _MAX_PATH
# undef HAVE_NTGUI
# undef DOS_NT
@@ -131,6 +127,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <binary-io.h>
#include <c-strcase.h>
#include <assert.h>
@@ -1002,13 +999,8 @@ main (int argc, char **argv)
linebuffer filename_lb;
bool help_asked = false;
ptrdiff_t len;
- char *optstring;
- int opt;
-
-
-#ifdef DOS_NT
- _fmode = O_BINARY; /* all of files are treated as binary files */
-#endif /* DOS_NT */
+ char *optstring;
+ int opt;
progname = argv[0];
nincluded_files = 0;
@@ -1195,15 +1187,10 @@ main (int argc, char **argv)
if (streq (tagfile, "-"))
{
tagf = stdout;
-#ifdef DOS_NT
- /* Switch redirected `stdout' to binary mode (setting `_fmode'
- doesn't take effect until after `stdout' is already open). */
- if (!isatty (fileno (stdout)))
- setmode (fileno (stdout), O_BINARY);
-#endif /* DOS_NT */
+ SET_BINARY (fileno (stdout));
}
else
- tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
+ tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb");
if (tagf == NULL)
pfatal (tagfile);
}
@@ -1306,7 +1293,7 @@ main (int argc, char **argv)
append_to_tagfile = true;
}
- tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
+ tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb");
if (tagf == NULL)
pfatal (tagfile);
put_entries (nodehead); /* write all the tags (CTAGS) */
@@ -1547,11 +1534,11 @@ process_file_name (char *file, language *lang)
if (real_name == compressed_name)
{
char *cmd = concat (compr->command, " ", real_name);
- inf = (FILE *) popen (cmd, "r");
+ inf = popen (cmd, "rb");
free (cmd);
}
else
- inf = fopen (real_name, "r");
+ inf = fopen (real_name, "rb");
if (inf == NULL)
{
perror (real_name);
@@ -5614,7 +5601,7 @@ analyse_regex (char *regex_arg)
char *regexfile = regex_arg + 1;
/* regexfile is a file containing regexps, one per line. */
- regexfp = fopen (regexfile, "r");
+ regexfp = fopen (regexfile, "rb");
if (regexfp == NULL)
pfatal (regexfile);
linebuffer_init (&regexbuf);
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/>. */
#include <stdio.h>
#include <ctype.h>
-#ifdef DOS_NT
-#include <fcntl.h>
-#if __DJGPP__ >= 2
-#include <io.h>
-#endif
-#endif
-#ifdef WINDOWSNT
-#include <io.h>
-#endif
+
+#include <binary-io.h>
#define DEFAULT_GROUPING 0x01
#define DEFAULT_BASE 16
@@ -155,20 +148,12 @@ main (int argc, char **argv)
if (un_flag)
{
- char buf[18];
-
-#ifdef DOS_NT
-#if (__DJGPP__ >= 2) || (defined WINDOWSNT)
- if (!isatty (fileno (stdout)))
- setmode (fileno (stdout), O_BINARY);
-#else
- (stdout)->_flag &= ~_IOTEXT; /* print binary */
- _setmode (fileno (stdout), O_BINARY);
-#endif
-#endif
+ SET_BINARY (fileno (stdout));
+
for (;;)
{
- register int i, c = 0, d;
+ int i, c = 0, d;
+ char buf[18];
#define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
@@ -210,15 +195,7 @@ main (int argc, char **argv)
}
else
{
-#ifdef DOS_NT
-#if (__DJGPP__ >= 2) || (defined WINDOWSNT)
- if (!isatty (fileno (fp)))
- setmode (fileno (fp), O_BINARY);
-#else
- (fp)->_flag &= ~_IOTEXT; /* read binary */
- _setmode (fileno (fp), O_BINARY);
-#endif
-#endif
+ SET_BINARY (fileno (fp));
address = 0;
string[0] = ' ';
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/>. */
#include <stdio.h>
#include <stdlib.h> /* config.h unconditionally includes this anyway */
-#ifdef MSDOS
-#include <fcntl.h>
-#endif /* MSDOS */
+
#ifdef WINDOWSNT
/* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this
is really just insurance. */
#undef fopen
-#include <fcntl.h>
#include <direct.h>
#endif /* WINDOWSNT */
+#include <binary-io.h>
+
#ifdef DOS_NT
/* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this
is really just insurance.
@@ -167,19 +166,7 @@ main (int argc, char **argv)
++i;
}
- /* Don't put CRs in the output file. */
-#ifdef MSDOS
- _fmode = O_BINARY;
-#if 0 /* Suspicion is that this causes hanging.
- So instead we require people to use -o on MSDOS. */
- (stdout)->_flag &= ~_IOTEXT;
- _setmode (fileno (stdout), O_BINARY);
-#endif
-#endif /* MSDOS */
-#ifdef WINDOWSNT
- _fmode = O_BINARY;
- _setmode (fileno (stdout), O_BINARY);
-#endif /* WINDOWSNT */
+ set_binary_mode (fileno (stdout), O_BINARY);
if (generate_globals)
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)
uid_t real_gid = getgid ();
uid_t priv_gid = getegid ();
-#ifdef WINDOWSNT
- /* Ensure all file i/o is in binary mode. */
- _fmode = _O_BINARY;
-#endif
-
delete_lockname = 0;
while ((c = getopt (argc, argv, ARGSTR)) != EOF)
@@ -304,7 +299,7 @@ main (int argc, char **argv)
memcpy (tempname, inname, inname_dirlen);
strcpy (tempname + inname_dirlen, "EXXXXXX");
- desc = mkostemp (tempname, 0);
+ desc = mkostemp (tempname, O_BINARY);
if (desc < 0)
{
int mkostemp_errno = errno;
@@ -358,12 +353,12 @@ main (int argc, char **argv)
#ifndef MAIL_USE_MMDF
#ifdef MAIL_USE_SYSTEM_LOCK
- indesc = open (inname, O_RDWR);
+ indesc = open (inname, O_RDWR | O_BINARY);
#else /* if not MAIL_USE_SYSTEM_LOCK */
- indesc = open (inname, O_RDONLY);
+ indesc = open (inname, O_RDONLY | O_BINARY);
#endif /* not MAIL_USE_SYSTEM_LOCK */
#else /* MAIL_USE_MMDF */
- indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
+ indesc = lk_open (inname, O_RDONLY | O_BINARY, 0, 0, 10);
#endif /* MAIL_USE_MMDF */
if (indesc < 0)
@@ -372,7 +367,7 @@ main (int argc, char **argv)
/* Make sure the user can read the output file. */
umask (umask (0) & 0377);
- outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ outdesc = open (outname, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
if (outdesc < 0)
pfatal_with_name (outname);
@@ -675,7 +670,7 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse
return EXIT_SUCCESS;
}
- mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ mbfi = open (outfile, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
if (mbfi < 0)
{
pop_close (server);