emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 3bbf517: Simplify binary I/O configuration


From: Paul Eggert
Subject: [Emacs-diffs] master 3bbf517: Simplify binary I/O configuration
Date: Fri, 20 Feb 2015 03:21:39 +0000

branch: master
commit 3bbf5170722d9e555307259763623c74240a2555
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Simplify binary I/O configuration
    
    * lib-src/etags.c: Include <sysstdio.h> rather than <stdio.h>.
    (process_file_name, analyze_regex): Use FOPEN_BINARY rather than
    hard-coded "b".
    * src/lread.c (Fload): Prefer FOPEN_TEXT and FOPEN_BINARY to
    #ifdef DOS_NT.
    * src/sysstdio.h: Add copyright notice.  Include <fcntl.h>.
    (FOPEN_BINARY, FOPEN_TEXT): New macros.
    * src/xfaces.c (Fx_load_color_file): Use FOPEN_TEXT, since POSIX
    doesn't guarantee that "t" will work.
---
 lib-src/ChangeLog |    7 +++++++
 lib-src/etags.c   |   15 ++++-----------
 src/ChangeLog     |    9 +++++++++
 src/lread.c       |   11 ++---------
 src/sysstdio.h    |   29 +++++++++++++++++++++++++++++
 src/xfaces.c      |    2 +-
 6 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 0551116..4ac9638 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-20  Paul Eggert  <address@hidden>
+
+       Simplify binary I/O configuration
+       * etags.c: Include <sysstdio.h> rather than <stdio.h>.
+       (process_file_name, analyze_regex): Use FOPEN_BINARY rather than
+       hard-coded "b".
+
 2015-02-19  Eli Zaretskii  <address@hidden>
 
        * etags.c (process_file_name) [!DOS_NT]: Use "r", not "rb" in the
diff --git a/lib-src/etags.c b/lib-src/etags.c
index cdac928..7f18755 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -122,7 +122,7 @@ char pot_etags_version[] = "@(#) pot revision number is 
17.38.1.4";
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <stdio.h>
+#include <sysstdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -1532,18 +1532,11 @@ process_file_name (char *file, language *lang)
   if (real_name == compressed_name)
     {
       char *cmd = concat (compr->command, " ", real_name);
-
-      /* Unix implementations of 'popen' generally don't support "rb", whereas
-        DOS_NT needs it.  */
-#ifdef DOS_NT
-      inf = popen (cmd, "rb");
-#else
-      inf = popen (cmd, "r");
-#endif
+      inf = popen (cmd, "r" FOPEN_BINARY);
       free (cmd);
     }
   else
-    inf = fopen (real_name, "rb");
+    inf = fopen (real_name, "r" FOPEN_BINARY);
   if (inf == NULL)
     {
       perror (real_name);
@@ -5607,7 +5600,7 @@ analyze_regex (char *regex_arg)
        char *regexfile = regex_arg + 1;
 
        /* regexfile is a file containing regexps, one per line. */
-       regexfp = fopen (regexfile, "rb");
+       regexfp = fopen (regexfile, "r" FOPEN_BINARY);
        if (regexfp == NULL)
          pfatal (regexfile);
        linebuffer_init (&regexbuf);
diff --git a/src/ChangeLog b/src/ChangeLog
index 38af1d8..1126dde 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2015-02-20  Paul Eggert  <address@hidden>
+
+       Simplify binary I/O configuration
+       * lread.c (Fload): Prefer FOPEN_TEXT and FOPEN_BINARY to #ifdef DOS_NT.
+       * sysstdio.h: Add copyright notice.  Include <fcntl.h>.
+       (FOPEN_BINARY, FOPEN_TEXT): New macros.
+       * xfaces.c (Fx_load_color_file): Use FOPEN_TEXT, since POSIX
+       doesn't guarantee that "t" will work.
+
 2015-02-19  Eli Zaretskii  <address@hidden>
 
        * keyboard.c (read_char): Make sure this_single_command_key_start
diff --git a/src/lread.c b/src/lread.c
index b42849f..ae17529 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1033,13 +1033,9 @@ Return t if the file exists and loads successfully.  */)
   bool compiled = 0;
   Lisp_Object handler;
   bool safe_p = 1;
-  const char *fmode = "r";
+  const char *fmode = "r" FOPEN_TEXT;
   int version;
 
-#ifdef DOS_NT
-  fmode = "rt";
-#endif /* DOS_NT */
-
   CHECK_STRING (file);
 
   /* If file name is magic, call the handler.  */
@@ -1223,10 +1219,7 @@ Return t if the file exists and loads successfully.  */)
          compiled = 1;
 
          efound = ENCODE_FILE (found);
-
-#ifdef DOS_NT
-         fmode = "rb";
-#endif /* DOS_NT */
+         fmode = "r" FOPEN_BINARY;
 
           /* openp already checked for newness, no point doing it again.
              FIXME would be nice to get a message when openp
diff --git a/src/sysstdio.h b/src/sysstdio.h
index e9dfb69..c97c4f8 100644
--- a/src/sysstdio.h
+++ b/src/sysstdio.h
@@ -1,2 +1,31 @@
+/* Standard I/O for Emacs.
+
+Copyright 2013-2015 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
 #include <stdio.h>
+
 extern FILE *emacs_fopen (char const *, char const *);
+
+#if O_BINARY
+# define FOPEN_BINARY "b"
+# define FOPEN_TEXT "t"
+#else
+# define FOPEN_BINARY ""
+# define FOPEN_TEXT ""
+#endif
diff --git a/src/xfaces.c b/src/xfaces.c
index d0fe872..fcfdbc0 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -6187,7 +6187,7 @@ where R,G,B are numbers between 0 and 255 and name is an 
arbitrary string.  */)
   abspath = Fexpand_file_name (filename, Qnil);
 
   block_input ();
-  fp = emacs_fopen (SSDATA (abspath), "rt");
+  fp = emacs_fopen (SSDATA (abspath), "r" FOPEN_TEXT);
   if (fp)
     {
       char buf[512];



reply via email to

[Prev in Thread] Current Thread [Next in Thread]