This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

include/binary-io.h


On Mon, Jul 14, 2008 at 03:57:43PM +0000, Jay wrote:
>         # /src/gcc/binutils/bin2c.c:89: warning: implicit declaration of function `_fileno"
>         # /src/gcc/binutils/bin2c.c:89: warning: implicit declaration of function `_setmode"

This should fix the warnings we were getting when building under Cygwin.

include/
	* binary-io.h: New file, imported from gnulib, but don't
	#include <fcntl.h> or <stdio.h>.
binutils/
	* sysdep.h: Include "binary-io.h".
	(O_BINARY): Don't define here.
	* bin2c.c (O_BINARY, O_TEXT, SET_BINARY): Don't define here.
	* strings.c: Likewise.
	(main): Remove #ifdef SET_BINARY.
	* Makefile.am: Run "make dep-am"
	* Makefile.in: Regenerate.
gprof/
	* gmon_io.h: Don't include sysdep.h here.
	(O_BINARY, SET_BINARY): Don't define here.
	* gmon_io.c: Include "binary-io.h".
	(gmon_out_read): Remove #ifdef SET_BINARY.
	* Makefile.am: Run "make dep-am"
	* Makefile.in: Regenerate.

Index: include/binary-io.h
===================================================================
RCS file: include/binary-io.h
diff -N include/binary-io.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ include/binary-io.h	25 Aug 2008 04:25:33 -0000
@@ -0,0 +1,62 @@
+/* Binary mode I/O.
+   Copyright (C) 2001, 2003, 2005, 2008 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/>.  */
+
+#ifndef _BINARY_H
+#define _BINARY_H
+
+/* Include this header after <fcntl.h> and <stdio.h>, because
+   systems that distinguish between text and binary I/O usually
+   define O_BINARY in <fcntl.h>, and the MSVC7 <stdio.h> doesn't
+   like to be included after '#define fileno ...'
+
+   We don't include <fcntl.h> here because not all systems have
+   that header.  */
+
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+#ifdef __BEOS__
+  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+#if O_BINARY
+# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
+#  include <io.h> /* declares setmode() */
+# else
+#  define setmode _setmode
+#  undef fileno
+#  define fileno _fileno
+# endif
+# ifdef __DJGPP__
+#  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) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
+# else
+#  define SET_BINARY(fd) setmode (fd, O_BINARY)
+# endif
+#else
+  /* On reasonable systems, binary I/O is the default.  */
+# undef O_BINARY
+# define O_BINARY 0
+# define SET_BINARY(fd) /* nothing */
+#endif
+
+#endif /* _BINARY_H */
Index: binutils/sysdep.h
===================================================================
RCS file: /cvs/src/src/binutils/sysdep.h,v
retrieving revision 1.4
diff -u -p -r1.4 sysdep.h
--- binutils/sysdep.h	28 Apr 2008 08:30:23 -0000	1.4
+++ binutils/sysdep.h	25 Aug 2008 03:59:42 -0000
@@ -1,6 +1,7 @@
 /* sysdep.h -- handle host dependencies for binutils
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -36,14 +37,6 @@
 #include "fopen-same.h"
 #endif
 
-#ifndef O_BINARY
-#ifdef  _O_BINARY
-#define O_BINARY _O_BINARY
-#else
-#define O_BINARY 0
-#endif
-#endif
-
 #include <errno.h>
 #ifndef errno
 extern int errno;
@@ -76,6 +69,8 @@ extern char *strrchr ();
 #endif
 #endif
 
+#include "binary-io.h"
+
 #if !HAVE_DECL_STPCPY
 extern char *stpcpy (char *, const char *);
 #endif
Index: binutils/bin2c.c
===================================================================
RCS file: /cvs/src/src/binutils/bin2c.c,v
retrieving revision 1.4
diff -u -p -r1.4 bin2c.c
--- binutils/bin2c.c	28 Apr 2008 08:30:23 -0000	1.4
+++ binutils/bin2c.c	25 Aug 2008 03:59:39 -0000
@@ -22,30 +22,6 @@
 #include "bfd.h"
 #include "bucomm.h"
 
-#if !defined O_TEXT && defined _O_TEXT
-  /* For MSC-compatible compilers.  */
-# define O_TEXT _O_TEXT
-#endif
-
-#ifdef __BEOS__
-  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
-# undef O_BINARY
-# undef O_TEXT
-#endif
-
-#if O_BINARY
-# ifndef __DJGPP__
-#  define setmode _setmode
-#  define fileno(_fp) _fileno (_fp)
-# endif /* not DJGPP */
-# define SET_BINARY(_f) \
-  do { if (!isatty (_f)) setmode (_f, O_BINARY); } while (0)
-#else
-# define SET_BINARY(f) (void) 0
-# define O_BINARY 0
-# define O_TEXT 0
-#endif /* O_BINARY */
-
 int
 main (int argc, char *argv[])
 {
Index: binutils/strings.c
===================================================================
RCS file: /cvs/src/src/binutils/strings.c,v
retrieving revision 1.41
diff -u -p -r1.41 strings.c
--- binutils/strings.c	28 Apr 2008 08:30:23 -0000	1.41
+++ binutils/strings.c	25 Aug 2008 03:59:39 -0000
@@ -66,18 +66,6 @@
 #include <sys/stat.h>
 #include "bucomm.h"
 
-/* Some platforms need to put stdin into binary mode, to read
-    binary files.  */
-#ifdef HAVE_SETMODE
-#ifdef _O_BINARY
-#define setmode _setmode
-#endif
-#if O_BINARY
-#include <io.h>
-#define SET_BINARY(f) do { if (!isatty (f)) setmode (f, O_BINARY); } while (0)
-#endif
-#endif
-
 #define STRING_ISGRAPHIC(c) \
       (   (c) >= 0 \
        && (c) <= 255 \
@@ -286,9 +274,7 @@ main (int argc, char **argv)
   if (optind >= argc)
     {
       datasection_only = FALSE;
-#ifdef SET_BINARY
       SET_BINARY (fileno (stdin));
-#endif
       print_strings ("{standard input}", stdin, 0, 0, 0, (char *) NULL);
       files_given = TRUE;
     }
Index: gprof/gmon_io.c
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.c,v
retrieving revision 1.25
diff -u -p -r1.25 gmon_io.c
--- gprof/gmon_io.c	5 Aug 2008 19:09:06 -0000	1.25
+++ gprof/gmon_io.c	25 Aug 2008 04:00:02 -0000
@@ -1,6 +1,6 @@
 /* gmon_io.c - Input and output from/to gmon.out files.
 
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
@@ -21,6 +21,7 @@
    02110-1301, USA.  */
 
 #include "gprof.h"
+#include "binary-io.h"
 #include "search_list.h"
 #include "source.h"
 #include "symtab.h"
@@ -300,9 +301,7 @@ gmon_out_read (const char *filename)
   if (strcmp (filename, "-") == 0)
     {
       ifp = stdin;
-#ifdef SET_BINARY
       SET_BINARY (fileno (stdin));
-#endif
     }
   else
     {
Index: gprof/gmon_io.h
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.h,v
retrieving revision 1.11
diff -u -p -r1.11 gmon_io.h
--- gprof/gmon_io.h	6 Jul 2007 10:40:34 -0000	1.11
+++ gprof/gmon_io.h	25 Aug 2008 04:00:02 -0000
@@ -1,6 +1,7 @@
 /* gmon_io.h
 
-   Copyright 2000, 2001, 2002, 2004, 2007 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002, 2004, 2007, 2008
+   Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -22,24 +23,6 @@
 #ifndef gmon_io_h
 #define gmon_io_h
 
-/* Some platforms need to put stdin into binary mode, to read
-   binary files.  */
-#include "sysdep.h"
-#ifdef HAVE_SETMODE
-#ifndef O_BINARY
-#ifdef _O_BINARY
-#define O_BINARY _O_BINARY
-#define setmode _setmode
-#else
-#define O_BINARY 0
-#endif
-#endif
-#if O_BINARY
-#include <io.h>
-#define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0)
-#endif
-#endif
-
 #define INPUT_HISTOGRAM		(1 << 0)
 #define INPUT_CALL_GRAPH	(1 << 1)
 #define INPUT_BB_COUNTS		(1 << 2)

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]