[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 7204577 2/2: Merge from gnulib
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 7204577 2/2: Merge from gnulib |
Date: |
Thu, 23 Feb 2017 12:15:12 -0500 (EST) |
branch: master
commit 7204577bf90ba8574a0199680626a5ae3f075554
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Merge from gnulib
This incorporates:
2017-02-16 xbinary-io: rename from xsetmode
2017-02-15 xsetmode: new module
* lib-src/etags.c (main):
* lib-src/hexl.c (main):
* src/emacs.c (main) [MSDOS]:
Prefer set_binary_mode to the obsolescent SET_BINARY.
* lib/binary-io.c, lib/binary-io.h: Copy from gnulib.
---
lib-src/etags.c | 2 +-
lib-src/hexl.c | 4 ++--
lib/binary-io.c | 35 ++++++++++++++++++++++++++++++++++-
lib/binary-io.h | 36 ++++++++++++++++++++++--------------
src/emacs.c | 4 ++--
5 files changed, 61 insertions(+), 20 deletions(-)
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 1b6ac83..39b90cc 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -1255,7 +1255,7 @@ main (int argc, char **argv)
if (streq (tagfile, "-"))
{
tagf = stdout;
- SET_BINARY (fileno (stdout));
+ set_binary_mode (STDOUT_FILENO, O_BINARY);
}
else
tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb");
diff --git a/lib-src/hexl.c b/lib-src/hexl.c
index 2c7e8c4..319ce8b 100644
--- a/lib-src/hexl.c
+++ b/lib-src/hexl.c
@@ -76,7 +76,7 @@ main (int argc, char **argv)
else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
{
un_flag = true;
- SET_BINARY (fileno (stdout));
+ set_binary_mode (fileno (stdout), O_BINARY);
}
else if (!strcmp (*argv, "-hex"))
/* Hex is the default and is only base supported. */;
@@ -109,7 +109,7 @@ main (int argc, char **argv)
{
fp = stdin;
if (!un_flag)
- SET_BINARY (fileno (stdin));
+ set_binary_mode (fileno (stdin), O_BINARY);
}
else
{
diff --git a/lib/binary-io.c b/lib/binary-io.c
index d828bcd..a7558b2 100644
--- a/lib/binary-io.c
+++ b/lib/binary-io.c
@@ -1,4 +1,37 @@
+/* Binary mode I/O.
+ Copyright 2017 Free Software Foundation, Inc.
+
+ This program 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.
+
+ This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
#include <config.h>
+
#define BINARY_IO_INLINE _GL_EXTERN_INLINE
#include "binary-io.h"
-typedef int dummy;
+
+#if defined __DJGPP__ || defined __EMX__
+# include <errno.h>
+# include <unistd.h>
+
+int
+__gl_setmode_check (int fd)
+{
+ if (isatty (fd))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ else
+ return 0;
+}
+#endif
diff --git a/lib/binary-io.h b/lib/binary-io.h
index f766439..9f1dde1 100644
--- a/lib/binary-io.h
+++ b/lib/binary-io.h
@@ -33,15 +33,12 @@ _GL_INLINE_HEADER_BEGIN
# define BINARY_IO_INLINE _GL_INLINE
#endif
-/* set_binary_mode (fd, mode)
- sets the binary/text I/O mode of file descriptor fd to the given mode
- (must be O_BINARY or O_TEXT) and returns the previous mode. */
#if O_BINARY
# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
# include <io.h> /* declares setmode() */
-# define set_binary_mode setmode
+# define __gl_setmode setmode
# else
-# define set_binary_mode _setmode
+# define __gl_setmode _setmode
# undef fileno
# define fileno _fileno
# endif
@@ -50,7 +47,7 @@ _GL_INLINE_HEADER_BEGIN
/* Use a function rather than a macro, to avoid gcc warnings
"warning: statement with no effect". */
BINARY_IO_INLINE int
-set_binary_mode (int fd, int mode)
+__gl_setmode (int fd, int mode)
{
(void) fd;
(void) mode;
@@ -58,18 +55,29 @@ set_binary_mode (int fd, int mode)
}
#endif
-/* SET_BINARY (fd);
- changes the file descriptor fd to perform binary I/O. */
#if defined __DJGPP__ || defined __EMX__
-# include <unistd.h> /* declares isatty() */
- /* Avoid putting stdin/stdout in binary mode if it is connected to
- the console, because that would make it impossible for the user
- to interrupt the program through Ctrl-C or Ctrl-Break. */
-# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd,
O_BINARY), 0) : 0))
+extern int __gl_setmode_check (int);
#else
-# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
+BINARY_IO_INLINE int
+__gl_setmode_check (int fd) { return 0; }
#endif
+/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
+ Return the old mode if successful, -1 (setting errno) on failure.
+ Ordinarily this function would be called 'setmode', since that is
+ its name on MS-Windows, but it is called 'set_binary_mode' here
+ to avoid colliding with a BSD function of another name. */
+
+BINARY_IO_INLINE int
+set_binary_mode (int fd, int mode)
+{
+ int r = __gl_setmode_check (fd);
+ return r != 0 ? r : __gl_setmode (fd, mode);
+}
+
+/* This macro is obsolescent. */
+#define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
+
_GL_INLINE_HEADER_END
#endif /* _BINARY_H */
diff --git a/src/emacs.c b/src/emacs.c
index e5305e2..a72f181 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -894,9 +894,9 @@ main (int argc, char **argv)
#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */
#ifdef MSDOS
- SET_BINARY (fileno (stdin));
+ set_binary_mode (STDIN_FILENO, O_BINARY);
fflush (stdout);
- SET_BINARY (fileno (stdout));
+ set_binary_mode (STDOUT_FILENO, O_BINARY);
#endif /* MSDOS */
/* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.