From 4ecd1df6f2ecb98d388082b154497ed61aa11e18 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 10 Jan 2019 22:28:15 -0500 Subject: [PATCH] Add configure option AVOID_WINDOWS_HANDLE If set, we avoid using Windows I/O HANDLE, which is disallowed in some versions of the Windows SDK, such as for Windows phones. QUtil::same_file will always return false in this case. Only applies to Windows builds. --- ChangeLog | 7 +++++++ autofiles.sums | 2 +- configure | 26 ++++++++++++++++++++++++++ configure.ac | 15 +++++++++++++++ libqpdf/QUtil.cc | 4 +++- libqpdf/qpdf/qpdf-config.h.in | 3 +++ 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f1e7f95..80560611 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-01-10 Jay Berkenbilt + * Add new configure option --enable-avoid-windows-handle, which + causes the symbol AVOID_WINDOWS_HANDLE to be defined. If set, we + avoid using Windows I/O HANDLE, which is disallowed in some + versions of the Windows SDK, such as for Windows phones. + QUtil::same_file will always return false in this case. Only + applies to Windows builds. + * Add new method QPDF::setImmediateCopyFrom. When called on a source QPDF object, streams can be copied FROM that object to other ones without having to keep the source QPDF or its input diff --git a/autofiles.sums b/autofiles.sums index 397f6892..21a8b47e 100644 --- a/autofiles.sums +++ b/autofiles.sums @@ -1,4 +1,4 @@ -b544741ebe32e6bf555703b4cbedcaef62553da29e3230df4ccb8351900e2378 configure.ac +8e191dc63d2709fcd089ff62dd022589d12892129616a6036fa7e39833dd5443 configure.ac 35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4 37f8897d5f68d7d484e5457832a8f190ddb7507fa2a467cb7ee2be40a4364643 m4/libtool.m4 e77ebba8361b36f14b4d0927173a034b98c5d05049697a9ded84d85eb99a7990 m4/ltoptions.m4 diff --git a/configure b/configure index eacc2b8c..5ff3564e 100755 --- a/configure +++ b/configure @@ -756,6 +756,7 @@ enable_libtool_lock enable_insecure_random enable_os_secure_random with_random +enable_avoid_windows_handle enable_external_libs with_windows_wordsize with_large_file_test_path @@ -1425,6 +1426,9 @@ Optional Features: --enable-os-secure-random whether to try to use OS-provided secure random numbers (default is yes) + --enable-avoid-windows-handle + whether to avoid use of HANDLE, useful for some + embedded Windows builds (default is no) --enable-external-libs whether to use external libraries distribution --disable-largefile omit support for large files --enable-ld-version-script @@ -15780,6 +15784,28 @@ _ACEOF fi +# Check whether --enable-avoid-windows-handle was given. +if test "${enable_avoid_windows_handle+set}" = set; then : + enableval=$enable_avoid_windows_handle; if test "$enableval" = "yes"; then + qpdf_AVOID_HANDLE=1; + else + qpdf_AVOID_HANDLE=0; + fi +else + qpdf_AVOID_HANDLE=0 +fi + +if test "$qpdf_AVOID_HANDLE" = "1"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define AVOID_WINDOWS_HANDLE 1" >>confdefs.h + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + USE_EXTERNAL_LIBS=0 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for whether to use external libraries distribution" >&5 $as_echo_n "checking for whether to use external libraries distribution... " >&6; } diff --git a/configure.ac b/configure.ac index fb76544e..dfef332f 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,21 @@ fi AX_RANDOM_DEVICE +AC_ARG_ENABLE(avoid-windows-handle, + AS_HELP_STRING([--enable-avoid-windows-handle], + [whether to avoid use of HANDLE, useful for some embedded Windows builds (default is no)]), + [if test "$enableval" = "yes"; then + qpdf_AVOID_HANDLE=1; + else + qpdf_AVOID_HANDLE=0; + fi], [qpdf_AVOID_HANDLE=0]) +if test "$qpdf_AVOID_HANDLE" = "1"; then + AC_MSG_RESULT(yes) + AC_DEFINE([AVOID_WINDOWS_HANDLE], [1], [Whether to avoid use of HANDLE in Windows]) +else + AC_MSG_RESULT(no) +fi + USE_EXTERNAL_LIBS=0 AC_MSG_CHECKING(for whether to use external libraries distribution) AC_ARG_ENABLE(external-libs, diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 2d307956..8424854b 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -214,13 +214,14 @@ QUtil::same_file(char const* name1, char const* name2) return false; } #ifdef _WIN32 + bool same = false; +# ifndef AVOID_WINDOWS_HANDLE HANDLE fh1 = CreateFile(name1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE fh2 = CreateFile(name2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); BY_HANDLE_FILE_INFORMATION fi1; BY_HANDLE_FILE_INFORMATION fi2; - bool same = false; if ((fh1 != INVALID_HANDLE_VALUE) && (fh2 != INVALID_HANDLE_VALUE) && GetFileInformationByHandle(fh1, &fi1) && @@ -239,6 +240,7 @@ QUtil::same_file(char const* name1, char const* name2) { CloseHandle(fh2); } +# endif return same; #else struct stat st1; diff --git a/libqpdf/qpdf/qpdf-config.h.in b/libqpdf/qpdf/qpdf-config.h.in index ccc3e463..e50a00b8 100644 --- a/libqpdf/qpdf/qpdf-config.h.in +++ b/libqpdf/qpdf/qpdf-config.h.in @@ -1,5 +1,8 @@ /* libqpdf/qpdf/qpdf-config.h.in. Generated from configure.ac by autoheader. */ +/* Whether to avoid use of HANDLE in Windows */ +#undef AVOID_WINDOWS_HANDLE + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H