aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-02-23 09:14:06 -0800
committerPaul Eggert2017-02-23 09:15:06 -0800
commit7204577bf90ba8574a0199680626a5ae3f075554 (patch)
tree46062d3c37fa6cc291b9e0ce25a2f28992217094
parent23e64facf9f74133c6bacedeec56ad782ae69b65 (diff)
downloademacs-7204577bf90ba8574a0199680626a5ae3f075554.tar.gz
emacs-7204577bf90ba8574a0199680626a5ae3f075554.zip
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.
-rw-r--r--lib-src/etags.c2
-rw-r--r--lib-src/hexl.c4
-rw-r--r--lib/binary-io.c35
-rw-r--r--lib/binary-io.h36
-rw-r--r--src/emacs.c4
5 files changed, 61 insertions, 20 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 1b6ac83c9a8..39b90cc6cbf 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -1255,7 +1255,7 @@ main (int argc, char **argv)
1255 if (streq (tagfile, "-")) 1255 if (streq (tagfile, "-"))
1256 { 1256 {
1257 tagf = stdout; 1257 tagf = stdout;
1258 SET_BINARY (fileno (stdout)); 1258 set_binary_mode (STDOUT_FILENO, O_BINARY);
1259 } 1259 }
1260 else 1260 else
1261 tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb"); 1261 tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb");
diff --git a/lib-src/hexl.c b/lib-src/hexl.c
index 2c7e8c44161..319ce8bc890 100644
--- a/lib-src/hexl.c
+++ b/lib-src/hexl.c
@@ -76,7 +76,7 @@ main (int argc, char **argv)
76 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de")) 76 else if (!strcmp (*argv, "-un") || !strcmp (*argv, "-de"))
77 { 77 {
78 un_flag = true; 78 un_flag = true;
79 SET_BINARY (fileno (stdout)); 79 set_binary_mode (fileno (stdout), O_BINARY);
80 } 80 }
81 else if (!strcmp (*argv, "-hex")) 81 else if (!strcmp (*argv, "-hex"))
82 /* Hex is the default and is only base supported. */; 82 /* Hex is the default and is only base supported. */;
@@ -109,7 +109,7 @@ main (int argc, char **argv)
109 { 109 {
110 fp = stdin; 110 fp = stdin;
111 if (!un_flag) 111 if (!un_flag)
112 SET_BINARY (fileno (stdin)); 112 set_binary_mode (fileno (stdin), O_BINARY);
113 } 113 }
114 else 114 else
115 { 115 {
diff --git a/lib/binary-io.c b/lib/binary-io.c
index d828bcd0153..a7558b20fd1 100644
--- a/lib/binary-io.c
+++ b/lib/binary-io.c
@@ -1,4 +1,37 @@
1/* Binary mode I/O.
2 Copyright 2017 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
1#include <config.h> 17#include <config.h>
18
2#define BINARY_IO_INLINE _GL_EXTERN_INLINE 19#define BINARY_IO_INLINE _GL_EXTERN_INLINE
3#include "binary-io.h" 20#include "binary-io.h"
4typedef int dummy; 21
22#if defined __DJGPP__ || defined __EMX__
23# include <errno.h>
24# include <unistd.h>
25
26int
27__gl_setmode_check (int fd)
28{
29 if (isatty (fd))
30 {
31 errno = EINVAL;
32 return -1;
33 }
34 else
35 return 0;
36}
37#endif
diff --git a/lib/binary-io.h b/lib/binary-io.h
index f766439e2fb..9f1dde108eb 100644
--- a/lib/binary-io.h
+++ b/lib/binary-io.h
@@ -33,15 +33,12 @@ _GL_INLINE_HEADER_BEGIN
33# define BINARY_IO_INLINE _GL_INLINE 33# define BINARY_IO_INLINE _GL_INLINE
34#endif 34#endif
35 35
36/* set_binary_mode (fd, mode)
37 sets the binary/text I/O mode of file descriptor fd to the given mode
38 (must be O_BINARY or O_TEXT) and returns the previous mode. */
39#if O_BINARY 36#if O_BINARY
40# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__ 37# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
41# include <io.h> /* declares setmode() */ 38# include <io.h> /* declares setmode() */
42# define set_binary_mode setmode 39# define __gl_setmode setmode
43# else 40# else
44# define set_binary_mode _setmode 41# define __gl_setmode _setmode
45# undef fileno 42# undef fileno
46# define fileno _fileno 43# define fileno _fileno
47# endif 44# endif
@@ -50,7 +47,7 @@ _GL_INLINE_HEADER_BEGIN
50 /* Use a function rather than a macro, to avoid gcc warnings 47 /* Use a function rather than a macro, to avoid gcc warnings
51 "warning: statement with no effect". */ 48 "warning: statement with no effect". */
52BINARY_IO_INLINE int 49BINARY_IO_INLINE int
53set_binary_mode (int fd, int mode) 50__gl_setmode (int fd, int mode)
54{ 51{
55 (void) fd; 52 (void) fd;
56 (void) mode; 53 (void) mode;
@@ -58,18 +55,29 @@ set_binary_mode (int fd, int mode)
58} 55}
59#endif 56#endif
60 57
61/* SET_BINARY (fd);
62 changes the file descriptor fd to perform binary I/O. */
63#if defined __DJGPP__ || defined __EMX__ 58#if defined __DJGPP__ || defined __EMX__
64# include <unistd.h> /* declares isatty() */ 59extern int __gl_setmode_check (int);
65 /* Avoid putting stdin/stdout in binary mode if it is connected to
66 the console, because that would make it impossible for the user
67 to interrupt the program through Ctrl-C or Ctrl-Break. */
68# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
69#else 60#else
70# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) 61BINARY_IO_INLINE int
62__gl_setmode_check (int fd) { return 0; }
71#endif 63#endif
72 64
65/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
66 Return the old mode if successful, -1 (setting errno) on failure.
67 Ordinarily this function would be called 'setmode', since that is
68 its name on MS-Windows, but it is called 'set_binary_mode' here
69 to avoid colliding with a BSD function of another name. */
70
71BINARY_IO_INLINE int
72set_binary_mode (int fd, int mode)
73{
74 int r = __gl_setmode_check (fd);
75 return r != 0 ? r : __gl_setmode (fd, mode);
76}
77
78/* This macro is obsolescent. */
79#define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
80
73_GL_INLINE_HEADER_END 81_GL_INLINE_HEADER_END
74 82
75#endif /* _BINARY_H */ 83#endif /* _BINARY_H */
diff --git a/src/emacs.c b/src/emacs.c
index e5305e27417..a72f1810d8a 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -894,9 +894,9 @@ main (int argc, char **argv)
894#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */ 894#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */
895 895
896#ifdef MSDOS 896#ifdef MSDOS
897 SET_BINARY (fileno (stdin)); 897 set_binary_mode (STDIN_FILENO, O_BINARY);
898 fflush (stdout); 898 fflush (stdout);
899 SET_BINARY (fileno (stdout)); 899 set_binary_mode (STDOUT_FILENO, O_BINARY);
900#endif /* MSDOS */ 900#endif /* MSDOS */
901 901
902 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case. 902 /* Skip initial setlocale if LC_ALL is "C", as it's not needed in that case.