From c2ce5476dcde1ab9a7651a4c8a7b29a398b435ce Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 14 Apr 2016 09:47:18 -0700 Subject: [PATCH] Simplify use of O_BINARY * src/callproc.c (call_process): * src/fileio.c (write_region): * src/filelock.c (read_lock_data): * src/image.c (x_find_image_fd): * src/lread.c (openp): * src/sysdep.c (init_random, emacs_fopen): * src/unexcw.c (unexec): Omit unnecessary use of O_BINARY, since emacs_open now arranges that for us. --- src/callproc.c | 3 +-- src/fileio.c | 4 ++-- src/filelock.c | 2 +- src/image.c | 2 +- src/lread.c | 3 +-- src/sysdep.c | 3 +-- src/unexcw.c | 4 ++-- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index 8578556b695..3a40626de48 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -565,8 +565,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, { /* Since CRLF is converted to LF within `decode_coding', we can always open a file with binary mode. */ - callproc_fd[CALLPROC_PIPEREAD] = emacs_open (tempfile, - O_RDONLY | O_BINARY, 0); + callproc_fd[CALLPROC_PIPEREAD] = emacs_open (tempfile, O_RDONLY, 0); if (callproc_fd[CALLPROC_PIPEREAD] < 0) { int open_errno = errno; diff --git a/src/fileio.c b/src/fileio.c index 0a14d64456b..78cc66d7a41 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4804,7 +4804,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, encoded_filename = ENCODE_FILE (filename); fn = SSDATA (encoded_filename); - open_flags = O_WRONLY | O_BINARY | O_CREAT; + open_flags = O_WRONLY | O_CREAT; open_flags |= EQ (mustbenew, Qexcl) ? O_EXCL : !NILP (append) ? 0 : O_TRUNC; if (NUMBERP (append)) offset = file_offset (append); @@ -4923,7 +4923,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, if (timespec_valid_p (modtime) && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system)) { - int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0); + int desc1 = emacs_open (fn, O_WRONLY, 0); if (desc1 >= 0) { struct stat st1; diff --git a/src/filelock.c b/src/filelock.c index c58484a639b..6db6daa3bba 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -485,7 +485,7 @@ read_lock_data (char *lfname, char lfinfo[MAX_LFINFO + 1]) while ((nbytes = readlinkat (AT_FDCWD, lfname, lfinfo, MAX_LFINFO + 1)) < 0 && errno == EINVAL) { - int fd = emacs_open (lfname, O_RDONLY | O_BINARY | O_NOFOLLOW, 0); + int fd = emacs_open (lfname, O_RDONLY | O_NOFOLLOW, 0); if (0 <= fd) { /* Use read, not emacs_read, since FD isn't unwind-protected. */ diff --git a/src/image.c b/src/image.c index 867450567c2..2a7c2ccc82d 100644 --- a/src/image.c +++ b/src/image.c @@ -2300,7 +2300,7 @@ x_find_image_fd (Lisp_Object file, int *pfd) happens, e.g., under Auto Image File Mode.) 'openp' didn't open the file, so we should, because the caller expects that. */ - fd = emacs_open (SSDATA (file_found), O_RDONLY | O_BINARY, 0); + fd = emacs_open (SSDATA (file_found), O_RDONLY, 0); } } else /* fd < 0, but not -2 */ diff --git a/src/lread.c b/src/lread.c index 91469230b7e..fedfcb807c8 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1578,8 +1578,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, } else { - int oflags = O_RDONLY + (NILP (predicate) ? 0 : O_BINARY); - fd = emacs_open (pfn, oflags, 0); + fd = emacs_open (pfn, O_RDONLY, 0); if (fd < 0) { if (errno != ENOENT) diff --git a/src/sysdep.c b/src/sysdep.c index 1e3b9f12128..3faa696d89f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2148,7 +2148,7 @@ init_random (void) { bool success = false; #ifndef WINDOWSNT - int fd = emacs_open ("/dev/urandom", O_RDONLY | O_BINARY, 0); + int fd = emacs_open ("/dev/urandom", O_RDONLY, 0); if (0 <= fd) { success = emacs_read (fd, &v, sizeof v) == sizeof v; @@ -2328,7 +2328,6 @@ emacs_fopen (char const *file, char const *mode) switch (*m++) { case '+': omode = O_RDWR; break; - case 'b': bflag = O_BINARY; break; case 't': bflag = O_TEXT; break; default: /* Ignore. */ break; } diff --git a/src/unexcw.c b/src/unexcw.c index 399e2c34dda..ea678dd4c25 100644 --- a/src/unexcw.c +++ b/src/unexcw.c @@ -275,9 +275,9 @@ unexec (const char *outfile, const char *infile) infile = add_exe_suffix_if_necessary (infile, infile_buffer); outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer); - fd_in = emacs_open (infile, O_RDONLY | O_BINARY, 0); + fd_in = emacs_open (infile, O_RDONLY, 0); assert (fd_in >= 0); - fd_out = emacs_open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755); + fd_out = emacs_open (outfile, O_RDWR | O_TRUNC | O_CREAT, 0755); assert (fd_out >= 0); for (;;) { -- 2.39.2