From 3319ef17d271118e08da767daad9341cbe67c4e0 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 18 Sep 2012 18:06:28 +0000 Subject: [PATCH] posix.c (O_BINARY): Define if not defined. * 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. From-SVN: r191443 --- libbacktrace/ChangeLog | 8 ++++++++ libbacktrace/config.h.in | 3 +++ libbacktrace/configure | 21 +++++++++++++++++++++ libbacktrace/configure.ac | 14 ++++++++++++++ libbacktrace/posix.c | 8 +++++++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index e7c3bcaa15b..15a94391a1e 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,11 @@ +2012-09-18 Ian Lance Taylor + + * 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. + 2012-09-18 Ian Lance Taylor * btest.c (test1, test2, test3, test4): Add the unused attribute. diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in index 6a31c53d028..090e8d86bc3 100644 --- a/libbacktrace/config.h.in +++ b/libbacktrace/config.h.in @@ -10,6 +10,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the fcntl function */ +#undef HAVE_FCNTL + /* Define if _Unwind_GetIPInfo is available. */ #undef HAVE_GETIPINFO diff --git a/libbacktrace/configure b/libbacktrace/configure index 518e99e0014..70ac451e0a4 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -11713,6 +11713,27 @@ if test "$ALLOC_FILE" = "alloc.lo"; then fi +# 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_fn_c_check_func "$LINENO" "fcntl" "ac_cv_func_fcntl" +if test "x$ac_cv_func_fcntl" = x""yes; then : + have_fcntl=yes +else + have_fcntl=no +fi + +fi +if test "$have_fcntl" = "yes"; then + +$as_echo "#define HAVE_FCNTL 1" >>confdefs.h + +fi + ac_fn_c_check_decl "$LINENO" "strnlen" "ac_cv_have_decl_strnlen" "$ac_includes_default" if test "x$ac_cv_have_decl_strnlen" = x""yes; then : ac_have_decl=1 diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index 495e23e5c68..250423d1943 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -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], diff --git a/libbacktrace/posix.c b/libbacktrace/posix.c index 0b76f1e94a1..01afc42b08e 100644 --- a/libbacktrace/posix.c +++ b/libbacktrace/posix.c @@ -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, backtrace_error_callback error_callback, { 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; }