Commit 7204577b authored by Paul Eggert's avatar Paul Eggert

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.
parent 23e64fac
......@@ -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);
tagf = fopen (tagfile, append_to_tagfile ? "ab" : "wb");
......@@ -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);
/* 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
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 <>. */
#include <config.h>
#include "binary-io.h"
typedef int dummy;
#if defined __DJGPP__ || defined __EMX__
# include <errno.h>
# include <unistd.h>
__gl_setmode_check (int fd)
if (isatty (fd))
errno = EINVAL;
return -1;
return 0;
......@@ -33,15 +33,12 @@ _GL_INLINE_HEADER_BEGIN
/* 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 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". */
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)
/* 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);
# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
__gl_setmode_check (int fd) { return 0; }
/* 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. */
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))
#endif /* _BINARY_H */
......@@ -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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment