Patchwork libbacktrace patch committed: Add some mingw support

login
register
mail settings
Submitter Ian Taylor
Date Sept. 18, 2012, 6:06 p.m.
Message ID <mcry5k7nr2w.fsf@google.com>
Download mbox | patch
Permalink /patch/184792/
State New
Headers show

Comments

Ian Taylor - Sept. 18, 2012, 6:06 p.m.
This patch to libbacktrace adds some support for mingw.  The executable
is opened with O_BINARY.  The fcntl function is not called.
Bootstrapped and ran libbacktrace testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


2012-09-18  Ian Lance Taylor  <iant@google.com>

	* posix.c (O_BINARY): Define if not defined.
	(backtrace_open): Pass O_BINARY to open.  Only call fcntl if
	HAVE_FCNTL is defined.
	* configure.ac: Test for the fcntl function.
	* configure, config.h.in: Rebuild.

Patch

Index: posix.c
===================================================================
--- posix.c	(revision 191432)
+++ posix.c	(working copy)
@@ -41,6 +41,10 @@  POSSIBILITY OF SUCH DAMAGE.  */
 #include "backtrace.h"
 #include "internal.h"
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
@@ -57,18 +61,20 @@  backtrace_open (const char *filename, ba
 {
   int descriptor;
 
-  descriptor = open (filename, O_RDONLY | O_CLOEXEC);
+  descriptor = open (filename, O_RDONLY | O_BINARY | O_CLOEXEC);
   if (descriptor < 0)
     {
       error_callback (data, filename, errno);
       return -1;
     }
 
+#ifdef HAVE_FCNTL
   /* Set FD_CLOEXEC just in case the kernel does not support
      O_CLOEXEC. It doesn't matter if this fails for some reason.
      FIXME: At some point it should be safe to only do this if
      O_CLOEXEC == 0.  */
   fcntl (descriptor, F_SETFD, FD_CLOEXEC);
+#endif
 
   return descriptor;
 }
Index: configure.ac
===================================================================
--- configure.ac	(revision 191435)
+++ configure.ac	(working copy)
@@ -201,6 +201,20 @@  if test "$ALLOC_FILE" = "alloc.lo"; then
 fi
 AC_SUBST(BACKTRACE_USES_MALLOC)
 
+# Check for the fcntl function.
+if test -n "${with_target_subdir}"; then
+   case "${host}" in
+   *-*-mingw*) have_fcntl=no ;;
+   *) have_fcntl=yes ;;
+   esac
+else
+  AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
+fi
+if test "$have_fcntl" = "yes"; then
+  AC_DEFINE([HAVE_FCNTL], 1,
+	    [Define to 1 if you have the fcntl function])
+fi
+
 AC_CHECK_DECLS(strnlen)
 
 AC_CACHE_CHECK([whether tests can run],