summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-02-19 19:20:35 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-02-19 19:21:32 -0800
commit3bbf5170722d9e555307259763623c74240a2555 (patch)
tree853912d230255ec479567a7feb0cb9d0506e9de4
parent12ab9571935d79c69ffab0fb1ea3f6e20f475860 (diff)
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.
-rw-r--r--lib-src/ChangeLog7
-rw-r--r--lib-src/etags.c15
-rw-r--r--src/ChangeLog9
-rw-r--r--src/lread.c11
-rw-r--r--src/sysstdio.h29
-rw-r--r--src/xfaces.c2
6 files changed, 52 insertions, 21 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 0551116470..4ac9638102 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-20 Paul Eggert <eggert@cs.ucla.edu>
+
+ 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 <eliz@gnu.org>
* 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 cdac928923..7f1875547c 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 38af1d83a6..1126dde745 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2015-02-20 Paul Eggert <eggert@cs.ucla.edu>
+
+ 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 <eliz@gnu.org>
* keyboard.c (read_char): Make sure this_single_command_key_start
diff --git a/src/lread.c b/src/lread.c
index b42849fc41..ae175296dd 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 e9dfb69605..c97c4f883f 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 d0fe8726cb..fcfdbc0ee4 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];