From af035310bddac3e2f58ae0a330bc6ef168e180f1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Apr 2022 23:59:34 +0200 Subject: [PATCH] Remove test for snprintf() from configure and elsewhere This is needed to work around a build failure when this test fails, as it spuriously does when cross-compiling for MinGW using v10 API package, see https://sourceforge.net/p/mingw-w64/bugs/935/ for more details. Of course, the fact that the build fails if snprintf() is unavailable is actually a bug, but in practice this function is available everywhere by now, so simply stop testing for it. This mostly cherry picks ceff22ee (Use C99 snprintf, 2021-01-31), but keeps the test for MSVC versions without vsnprintf() for compatibility. --- .appveyor.yml | 2 +- CMakeLists.txt | 5 ----- configure | 16 +------------ configure.ac | 3 +-- libtiff/tif_config.h.cmake.in | 3 --- libtiff/tif_config.h.in | 3 --- libtiff/tiffiop.h | 6 ----- port/CMakeLists.txt | 3 --- port/Makefile.am | 1 - port/Makefile.in | 14 +++++------- port/Makefile.vc | 1 - port/libport.h | 9 -------- port/snprintf.c | 42 ----------------------------------- 13 files changed, 8 insertions(+), 100 deletions(-) delete mode 100644 port/snprintf.c diff --git a/.appveyor.yml b/.appveyor.yml index 04369ec6..828b6f78 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -83,7 +83,7 @@ build_script: - 'if %compiler%==mingw-cmake cmake --build . --config %configuration% --target install' - 'if %compiler%==vc14-cmake cmake --build . --config %configuration% --target install' - 'if %compiler%==vc9-cmake cmake --build . --config %configuration% --target install' - - 'if %compiler%==vc14-nmake nmake /f Makefile.vc EXTRAFLAGS=/DHAVE_SNPRINTF=1' + - 'if %compiler%==vc14-nmake nmake /f Makefile.vc' - 'if %compiler%==vc14-nmake mkdir %AV_TIFF_INSTALL%' - 'if %compiler%==vc14-nmake mkdir %AV_TIFF_INSTALL%\bin' - 'if %compiler%==vc14-nmake mkdir %AV_TIFF_INSTALL%\lib' diff --git a/CMakeLists.txt b/CMakeLists.txt index efe857df..feb32738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,7 +376,6 @@ endif() check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP) check_symbol_exists(setmode "unistd.h" HAVE_SETMODE) -check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP) check_symbol_exists(strtol "stdlib.h" HAVE_STRTOL) check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) @@ -385,10 +384,6 @@ check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) check_symbol_exists(getopt "unistd.h;stdio.h" HAVE_GETOPT) check_symbol_exists(lfind "search.h" HAVE_LFIND) -if(NOT HAVE_SNPRINTF) - add_definitions(-DNEED_LIBPORT) -endif() - # CPU bit order set(HOST_FILLORDER FILLORDER_MSB2LSB) if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR diff --git a/configure b/configure index 12a63232..516431ae 100755 --- a/configure +++ b/configure @@ -18158,7 +18158,7 @@ cat >>confdefs.h <<_ACEOF _ACEOF -for ac_func in mmap setmode snprintf +for ac_func in mmap setmode do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -18185,20 +18185,6 @@ esac fi -ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf" -if test "x$ac_cv_func_snprintf" = xyes; then : - $as_echo "#define HAVE_SNPRINTF 1" >>confdefs.h - -else - case " $LIBOBJS " in - *" snprintf.$ac_objext "* ) ;; - *) LIBOBJS="$LIBOBJS snprintf.$ac_objext" - ;; -esac - -fi - - ac_fn_c_check_func "$LINENO" "strcasecmp" "ac_cv_func_strcasecmp" if test "x$ac_cv_func_strcasecmp" = xyes; then : $as_echo "#define HAVE_STRCASECMP 1" >>confdefs.h diff --git a/configure.ac b/configure.ac index a2242330..314d7d1e 100644 --- a/configure.ac +++ b/configure.ac @@ -407,11 +407,10 @@ AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_T,$PTRDIFF_T,[Pointer difference type]) AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_FORMAT,$PTRDIFF_FORMAT,[Pointer difference type formatter]) dnl Checks for library functions. -AC_CHECK_FUNCS([mmap setmode snprintf]) +AC_CHECK_FUNCS([mmap setmode]) dnl Will use local replacements for unavailable functions AC_REPLACE_FUNCS(getopt) -AC_REPLACE_FUNCS(snprintf) AC_REPLACE_FUNCS(strcasecmp) AC_REPLACE_FUNCS(strtol) AC_REPLACE_FUNCS(strtoll) diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in index 24144603..1460505e 100644 --- a/libtiff/tif_config.h.cmake.in +++ b/libtiff/tif_config.h.cmake.in @@ -68,9 +68,6 @@ /* Define to 1 if you have the `setmode' function. */ #cmakedefine HAVE_SETMODE 1 -/* Define to 1 if you have the `snprintf' function. */ -#cmakedefine HAVE_SNPRINTF 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_STDINT_H 1 diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in index 30afd7a1..4b7522ca 100644 --- a/libtiff/tif_config.h.in +++ b/libtiff/tif_config.h.in @@ -92,9 +92,6 @@ /* Define to 1 if you have the `setmode' function. */ #undef HAVE_SETMODE -/* Define to 1 if you have the `snprintf' function. */ -#undef HAVE_SNPRINTF - /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h index 59fa8f0b..040014ae 100644 --- a/libtiff/tiffiop.h +++ b/libtiff/tiffiop.h @@ -55,12 +55,6 @@ extern void *lfind(const void *, const void *, size_t *, size_t, int (*)(const void *, const void *)); #endif -#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF) -#undef snprintf -#define snprintf _TIFF_snprintf_f -extern int snprintf(char* str, size_t size, const char* format, ...); -#endif - #include "tiffio.h" #include "tif_dir.h" diff --git a/port/CMakeLists.txt b/port/CMakeLists.txt index b7eb3a29..d3420865 100644 --- a/port/CMakeLists.txt +++ b/port/CMakeLists.txt @@ -41,9 +41,6 @@ endif() if(NOT HAVE_LFIND) list(APPEND port_USED_FILES lfind.c) endif() -if(MSVC AND NOT HAVE_SNPRINTF) - list(APPEND port_USED_FILES snprintf.c) -endif() if(NOT HAVE_STRCASECMP) list(APPEND port_USED_FILES strcasecmp.c) endif() diff --git a/port/Makefile.am b/port/Makefile.am index 250479fe..52d3cafc 100644 --- a/port/Makefile.am +++ b/port/Makefile.am @@ -27,7 +27,6 @@ EXTRA_DIST = \ CMakeLists.txt \ Makefile.vc \ libport.h \ - snprintf.c \ _strtol.h \ _strtoul.h diff --git a/port/Makefile.in b/port/Makefile.in index 83ce6f14..40aad9ec 100644 --- a/port/Makefile.in +++ b/port/Makefile.in @@ -151,10 +151,9 @@ DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/libtiff depcomp = $(SHELL) $(top_srcdir)/config/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = $(DEPDIR)/getopt.Plo $(DEPDIR)/lfind.Plo \ - $(DEPDIR)/snprintf.Plo $(DEPDIR)/strcasecmp.Plo \ - $(DEPDIR)/strtol.Plo $(DEPDIR)/strtoll.Plo \ - $(DEPDIR)/strtoul.Plo $(DEPDIR)/strtoull.Plo \ - ./$(DEPDIR)/dummy.Plo + $(DEPDIR)/strcasecmp.Plo $(DEPDIR)/strtol.Plo \ + $(DEPDIR)/strtoll.Plo $(DEPDIR)/strtoul.Plo \ + $(DEPDIR)/strtoull.Plo ./$(DEPDIR)/dummy.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -201,8 +200,8 @@ am__define_uniq_tagged_files = \ ETAGS = etags CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/depcomp \ - getopt.c lfind.c snprintf.c strcasecmp.c strtol.c strtoll.c \ - strtoul.c strtoull.c + getopt.c lfind.c strcasecmp.c strtol.c strtoll.c strtoul.c \ + strtoull.c DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -420,7 +419,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/lfind.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/snprintf.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strcasecmp.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strtol.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strtoll.Plo@am__quote@ # am--include-marker @@ -588,7 +586,6 @@ clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ distclean: distclean-am -rm -f $(DEPDIR)/getopt.Plo -rm -f $(DEPDIR)/lfind.Plo - -rm -f $(DEPDIR)/snprintf.Plo -rm -f $(DEPDIR)/strcasecmp.Plo -rm -f $(DEPDIR)/strtol.Plo -rm -f $(DEPDIR)/strtoll.Plo @@ -642,7 +639,6 @@ installcheck-am: maintainer-clean: maintainer-clean-am -rm -f $(DEPDIR)/getopt.Plo -rm -f $(DEPDIR)/lfind.Plo - -rm -f $(DEPDIR)/snprintf.Plo -rm -f $(DEPDIR)/strcasecmp.Plo -rm -f $(DEPDIR)/strtol.Plo -rm -f $(DEPDIR)/strtoll.Plo diff --git a/port/Makefile.vc b/port/Makefile.vc index e4471af5..fd9e9fbe 100644 --- a/port/Makefile.vc +++ b/port/Makefile.vc @@ -64,7 +64,6 @@ STRTOULL_OBJ = strtoull.obj INCL = -I..\libtiff OBJ = \ - snprintf.obj \ strcasecmp.obj \ $(STRTOL_OBJ) \ $(STRTOUL_OBJ) \ diff --git a/port/libport.h b/port/libport.h index 9f2dace1..275914af 100644 --- a/port/libport.h +++ b/port/libport.h @@ -59,13 +59,4 @@ lfind(const void *key, const void *base, size_t *nmemb, size_t size, int(*compar)(const void *, const void *)); #endif -#if !defined(HAVE_SNPRINTF) -#undef vsnprintf -#define vsnprintf _TIFF_vsnprintf_f - -#undef snprintf -#define snprintf _TIFF_snprintf_f -int snprintf(char* str, size_t size, const char* format, ...); -#endif - #endif /* ndef _LIBPORT_ */ diff --git a/port/snprintf.c b/port/snprintf.c deleted file mode 100644 index 3542ab75..00000000 --- a/port/snprintf.c +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Workaround for lack of snprintf(3) in Visual Studio. See - * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996 - * It's a trivial wrapper around the builtin _vsnprintf_s and - * _vscprintf functions. - */ - -#ifdef _MSC_VER - -#include -#include -#include "libport.h" - -int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap) -{ - int count = -1; - - if (size != 0) -#if _MSC_VER <= 1310 - count = _vsnprintf(str, size, format, ap); -#else - count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); -#endif - if (count == -1) - count = _vscprintf(format, ap); - - return count; -} - -int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...) -{ - int count; - va_list ap; - - va_start(ap, format); - count = vsnprintf(str, size, format, ap); - va_end(ap); - - return count; -} - -#endif // _MSC_VER