aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2017-02-23 09:14:06 -0800
committerPaul Eggert2017-02-23 09:15:06 -0800
commit7204577bf90ba8574a0199680626a5ae3f075554 (patch)
tree46062d3c37fa6cc291b9e0ce25a2f28992217094 /lib
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/binary-io.c35
-rw-r--r--lib/binary-io.h36
2 files changed, 56 insertions, 15 deletions
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 */