diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-02-23 09:14:06 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-02-23 09:15:06 -0800 |
commit | 7204577bf90ba8574a0199680626a5ae3f075554 (patch) | |
tree | 46062d3c37fa6cc291b9e0ce25a2f28992217094 /lib | |
parent | 23e64facf9f74133c6bacedeec56ad782ae69b65 (diff) | |
download | emacs-7204577bf90ba8574a0199680626a5ae3f075554.tar.gz |
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.c | 35 | ||||
-rw-r--r-- | lib/binary-io.h | 36 |
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 @@ +/* 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 f766439e2fb..9f1dde108eb 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 */ |