From 8ba4a1c8946016d6b82d854d6fbcdc7ed9d0e513 Mon Sep 17 00:00:00 2001 From: Bob Friesenhahn Date: Wed, 19 Aug 2015 02:31:04 +0000 Subject: [PATCH] Support large files under Windows using tif_unix.c and libtiff tools. --- ChangeLog | 8 +++++ configure | 69 +++++++++++++++++++++++++++++++++++++++++ configure.ac | 4 +++ libtiff/Makefile.vc | 6 ++-- libtiff/tif_codec.c | 5 ++- libtiff/tif_config.h.in | 6 ++++ libtiff/tif_print.c | 8 ++--- libtiff/tif_unix.c | 57 +++++++++++++++++++++++++++------- libtiff/tif_vms.c | 8 ++--- libtiff/tiffiop.h | 46 ++++++++++++++++++++++++++- port/Makefile.vc | 3 +- port/libport.h | 7 ++++- port/snprintf.c | 1 + tools/bmp2tiff.c | 17 +++++----- tools/fax2ps.c | 5 +-- tools/raw2tiff.c | 25 ++++++++------- tools/tiff2pdf.c | 4 +-- tools/tiffcrop.c | 4 +-- tools/tiffdump.c | 19 +++--------- 19 files changed, 233 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 40c47e19..41716a15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-08-18 Bob Friesenhahn + + * libtiff/tiffiop.h: First cut at supporting large files under + Microsoft Windows using tif_unix.c and the libtiff tools. This + only works if the Windows CDK is new enough to support the APIs + used (Visual C++ 2005 or later). Support for large files is not + actually tested yet. + 2015-08-15 Bob Friesenhahn * libtiff/tif_jpeg.c: Applied patch by Räisä Olli to assure that diff --git a/configure b/configure index 5b47d8b2..6f01e2b0 100755 --- a/configure +++ b/configure @@ -17244,6 +17244,75 @@ $as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGEFILE_SOURCE value needed for large files" >&5 +$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; } +if ${ac_cv_sys_largefile_source+:} false; then : + $as_echo_n "(cached) " >&6 +else + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include /* for off_t */ + #include +int +main () +{ +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_sys_largefile_source=no; break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _LARGEFILE_SOURCE 1 +#include /* for off_t */ + #include +int +main () +{ +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_sys_largefile_source=1; break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_cv_sys_largefile_source=unknown + break +done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_source" >&5 +$as_echo "$ac_cv_sys_largefile_source" >&6; } +case $ac_cv_sys_largefile_source in #( + no | unknown) ;; + *) +cat >>confdefs.h <<_ACEOF +#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source +_ACEOF +;; +esac +rm -rf conftest* + +# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug +# in glibc 2.1.3, but that breaks too many other things. +# If you want fseeko and ftello with glibc, upgrade to a fixed glibc. +if test $ac_cv_sys_largefile_source != unknown; then + +$as_echo "#define HAVE_FSEEKO 1" >>confdefs.h + +fi + + ac_fn_c_check_decl "$LINENO" "optarg" "ac_cv_have_decl_optarg" "$ac_includes_default" if test "x$ac_cv_have_decl_optarg" = xyes; then : ac_have_decl=1 diff --git a/configure.ac b/configure.ac index b033bca3..cba067fc 100644 --- a/configure.ac +++ b/configure.ac @@ -182,6 +182,10 @@ AC_TYPE_SIZE_T AC_HEADER_TIME AC_STRUCT_TM +dnl If the `fseeko' function is available, define `HAVE_FSEEKO'. Define +dnl `_LARGEFILE_SOURCE' if necessary. +AC_FUNC_FSEEKO + dnl Check if optarg (and presumably related externs) already declared in headers AC_CHECK_DECLS([optarg]) diff --git a/libtiff/Makefile.vc b/libtiff/Makefile.vc index 42792ba1..b7309154 100644 --- a/libtiff/Makefile.vc +++ b/libtiff/Makefile.vc @@ -1,4 +1,4 @@ -# $Id: Makefile.vc,v 1.22 2009-06-23 18:25:43 fwarmerdam Exp $ +# $Id: Makefile.vc,v 1.23 2015-08-19 02:31:04 bfriesen Exp $ # # Copyright (C) 2004, Andrey Kiselev # @@ -87,11 +87,11 @@ tiffconf.h: tiffconf.vc.h copy tiffconf.vc.h tiffconf.h libtiff.lib: tif_config.h tiffconf.h $(OBJ) - $(AR) /out:libtiff.lib $(OBJ) $(LIBS) + $(AR) /out:libtiff.lib ..\port\libport.lib $(OBJ) $(LIBS) $(DLLNAME): tif_config.h tiffconf.h libtiff.def $(OBJ) $(LD) /debug /dll /def:libtiff.def /out:$(DLLNAME) \ - /implib:libtiff_i.lib $(OBJ) $(LIBS) + /implib:libtiff_i.lib ..\port\libport.lib $(OBJ) $(LIBS) clean: -del tif_config.h tiffconf.h diff --git a/libtiff/tif_codec.c b/libtiff/tif_codec.c index 703e87d5..7cb46f63 100644 --- a/libtiff/tif_codec.c +++ b/libtiff/tif_codec.c @@ -1,4 +1,4 @@ -/* $Id: tif_codec.c,v 1.16 2013-05-02 14:44:29 tgl Exp $ */ +/* $Id: tif_codec.c,v 1.17 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -108,8 +108,7 @@ _notConfigured(TIFF* tif) const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); char compression_code[20]; - snprintf(compression_code, sizeof(compression_code), "%d", - tif->tif_dir.td_compression ); + sprintf(compression_code, "%d",tif->tif_dir.td_compression ); TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s compression support is not configured", c ? c->name : compression_code ); diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in index 6c336a9b..a4b2e60a 100644 --- a/libtiff/tif_config.h.in +++ b/libtiff/tif_config.h.in @@ -40,6 +40,9 @@ /* Define to 1 if you have the `floor' function. */ #undef HAVE_FLOOR +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#undef HAVE_FSEEKO + /* Define to 1 if you have the `getopt' function. */ #undef HAVE_GETOPT @@ -385,6 +388,9 @@ /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#undef _LARGEFILE_SOURCE + /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES diff --git a/libtiff/tif_print.c b/libtiff/tif_print.c index 9e27ae25..7b1a4222 100644 --- a/libtiff/tif_print.c +++ b/libtiff/tif_print.c @@ -1,4 +1,4 @@ -/* $Id: tif_print.c,v 1.61 2012-12-12 22:50:18 tgl Exp $ */ +/* $Id: tif_print.c,v 1.62 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -35,7 +35,7 @@ #include static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars); +_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars); static const char *photoNames[] = { "min-is-white", /* PHOTOMETRIC_MINISWHITE */ @@ -395,7 +395,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) for (cp = td->td_inknames; i > 0 && cp < td->td_inknames + td->td_inknameslen; cp = strchr(cp,'\0')+1, i--) { - int max_chars = + size_t max_chars = td->td_inknameslen - (cp - td->td_inknames); fputs(sep, fd); _TIFFprintAsciiBounded(fd, cp, max_chars); @@ -679,7 +679,7 @@ _TIFFprintAscii(FILE* fd, const char* cp) } static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars) +_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars) { for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) { const char* tp; diff --git a/libtiff/tif_unix.c b/libtiff/tif_unix.c index e96841a4..81e9d665 100644 --- a/libtiff/tif_unix.c +++ b/libtiff/tif_unix.c @@ -1,4 +1,4 @@ -/* $Id: tif_unix.c,v 1.26 2015-06-16 15:33:17 erouault Exp $ */ +/* $Id: tif_unix.c,v 1.27 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -55,6 +55,10 @@ #include "tiffiop.h" + +#define TIFF_IO_MAX 2147483647U + + typedef union fd_as_handle_union { int fd; @@ -65,42 +69,71 @@ static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size) { fd_as_handle_union_t fdh; - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) + const size_t bytes_total = (size_t) size; + size_t bytes_read; + tmsize_t count = -1; + if ((tmsize_t) bytes_total != size) { errno=EINVAL; return (tmsize_t) -1; } fdh.h = fd; - return ((tmsize_t) read(fdh.fd, buf, size_io)); + for (bytes_read=0; bytes_read < bytes_total; bytes_read+=count) + { + char *buf_offset = (char *) buf+bytes_read; + size_t io_size = bytes_total-bytes_read; + if (io_size > TIFF_IO_MAX) + io_size = TIFF_IO_MAX; + count=read(fdh.fd, buf_offset, (TIFFIOSize_t) io_size); + if (count <= 0) + break; + } + if (count < 0) + return (tmsize_t)-1; + return (tmsize_t) bytes_read; } static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) { fd_as_handle_union_t fdh; - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) + const size_t bytes_total = (size_t) size; + size_t bytes_written; + tmsize_t count = -1; + if ((tmsize_t) bytes_total != size) { errno=EINVAL; return (tmsize_t) -1; } fdh.h = fd; - return ((tmsize_t) write(fdh.fd, buf, size_io)); + for (bytes_written=0; bytes_written < bytes_total; bytes_written+=count) + { + const char *buf_offset = (char *) buf+bytes_written; + size_t io_size = bytes_total-bytes_written; + if (io_size > TIFF_IO_MAX) + io_size = TIFF_IO_MAX; + count=write(fdh.fd, buf_offset, (TIFFIOSize_t) io_size); + if (count <= 0) + break; + } + if (count < 0) + return (tmsize_t)-1; + return (tmsize_t) bytes_written; + /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */ } static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence) { fd_as_handle_union_t fdh; - off_t off_io = (off_t) off; + _TIFF_off_t off_io = (_TIFF_off_t) off; if ((uint64) off_io != off) { errno=EINVAL; return (uint64) -1; /* this is really gross */ } fdh.h = fd; - return((uint64)lseek(fdh.fd,off_io,whence)); + return((uint64)_TIFF_lseek_f(fdh.fd,off_io,whence)); } static int @@ -114,10 +147,10 @@ _tiffCloseProc(thandle_t fd) static uint64 _tiffSizeProc(thandle_t fd) { - struct stat sb; + _TIFF_stat_s sb; fd_as_handle_union_t fdh; fdh.h = fd; - if (fstat(fdh.fd,&sb)<0) + if (_TIFF_fstat_f(fdh.fd,&sb)<0) return(0); else return((uint64)sb.st_size); @@ -245,7 +278,7 @@ TIFFOpenW(const wchar_t* name, const char* mode) fd = _wopen(name, m, 0666); if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); + TIFFErrorExt(0, module, "%ls: Cannot open", name); return ((TIFF *)0); } diff --git a/libtiff/tif_vms.c b/libtiff/tif_vms.c index 359f8ec3..c49587aa 100644 --- a/libtiff/tif_vms.c +++ b/libtiff/tif_vms.c @@ -1,4 +1,4 @@ -/* $Id: tif_vms.c,v 1.12 2012-11-18 17:51:52 bfriesen Exp $ */ +/* $Id: tif_vms.c,v 1.13 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -66,7 +66,7 @@ _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) static toff_t _tiffSeekProc(thandle_t fd, toff_t off, int whence) { - return ((toff_t) lseek((int) fd, (off_t) off, whence)); + return ((toff_t) _TIFF_lseek_f((int) fd, (_TIFF_off_t) off, whence)); } static int @@ -80,8 +80,8 @@ _tiffCloseProc(thandle_t fd) static toff_t _tiffSizeProc(thandle_t fd) { - struct stat sb; - return (toff_t) (fstat((int) fd, &sb) < 0 ? 0 : sb.st_size); + _TIFF_stat_s sb; + return (toff_t) (_TIFF_fstat_f((int) fd, &sb) < 0 ? 0 : sb.st_size); } #ifdef HAVE_MMAP diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h index 41686eb0..9ad30fc6 100644 --- a/libtiff/tiffiop.h +++ b/libtiff/tiffiop.h @@ -1,4 +1,4 @@ -/* $Id: tiffiop.h,v 1.85 2015-06-25 02:28:01 bfriesen Exp $ */ +/* $Id: tiffiop.h,v 1.86 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -58,6 +58,8 @@ extern void *lfind(const void *, const void *, size_t *, size_t, #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 @@ -262,6 +264,48 @@ struct tiff { #define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0])) +/* + Support for large files. + + Windows read/write APIs support only 'unsigned int' rather than 'size_t'. + Windows off_t is only 32-bit, even in 64-bit builds. +*/ +#if defined(HAVE_FSEEKO) +/* + Use fseeko() and ftello() if they are available since they use + 'off_t' rather than 'long'. It is wrong to use fseeko() and + ftello() only on systems with special LFS support since some systems + (e.g. FreeBSD) support a 64-bit off_t by default. +*/ +#if defined(HAVE_FSEEKO) +# define fseek(stream,offset,whence) fseeko(stream,offset,whence) +# define ftell(stream,offset,whence) ftello(stream,offset,whence) +#endif +#endif +#if defined(__WIN32__) && \ + !(defined(_MSC_VER) && _MSC_VER < 1400)/* && \ */ + /* !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800) */ +typedef unsigned int TIFFIOSize_t; +#define _TIFF_lseek_f(fildes,offset,whence) _lseeki64(fildes,/* __int64 */ offset,whence) +/* #define _TIFF_tell_f(fildes) /\* __int64 *\/ _telli64(fildes) */ +#define _TIFF_fseek_f(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence) +#define _TIFF_fstat_f(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff) +/* #define _TIFF_ftell_f(stream) /\* __int64 *\/ _ftelli64(stream) */ +/* #define _TIFF_stat_f(path,stat_buff) _stati64(path,/\* struct _stati64 *\/ stat_buff) */ +#define _TIFF_stat_s struct _stati64 +#define _TIFF_off_t __int64 +#else +typedef size_t TIFFIOSize_t; +#define _TIFF_lseek_f(fildes,offset,whence) lseek(fildes,offset,whence) +/* #define _TIFF_tell_f(fildes) (_TIFF_lseek_f(fildes,0,SEEK_CUR)) */ +#define _TIFF_fseek_f(stream,offset,whence) fseek(stream,offset,whence) +#define _TIFF_fstat_f(fildes,stat_buff) fstat(fildes,stat_buff) +/* #define _TIFF_ftell_f(stream) ftell(stream) */ +/* #define _TIFF_stat_f(path,stat_buff) stat(path,stat_buff) */ +#define _TIFF_stat_s struct stat +#define _TIFF_off_t off_t +#endif + #if defined(__cplusplus) extern "C" { #endif diff --git a/port/Makefile.vc b/port/Makefile.vc index fa98f3f8..bde48048 100644 --- a/port/Makefile.vc +++ b/port/Makefile.vc @@ -1,4 +1,4 @@ -# $Id: Makefile.vc,v 1.4 2006-03-23 14:54:02 dron Exp $ +# $Id: Makefile.vc,v 1.5 2015-08-19 02:31:04 bfriesen Exp $ # # Copyright (C) 2004, Andrey Kiselev # @@ -29,6 +29,7 @@ !INCLUDE ..\nmake.opt OBJ = \ + snprintf.obj \ strcasecmp.obj \ getopt.obj diff --git a/port/libport.h b/port/libport.h index 8e73e0a3..d9b04215 100644 --- a/port/libport.h +++ b/port/libport.h @@ -1,4 +1,4 @@ -/* $Id: libport.h,v 1.4 2015-07-04 22:09:27 bfriesen Exp $ */ +/* $Id: libport.h,v 1.5 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 2009 Frank Warmerdam @@ -49,6 +49,11 @@ lfind(const void *key, const void *base, size_t *nmemb, size_t size, #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 diff --git a/port/snprintf.c b/port/snprintf.c index ddbf6581..ce261291 100644 --- a/port/snprintf.c +++ b/port/snprintf.c @@ -9,6 +9,7 @@ #include #include +#include "libport.h" int vsnprintf(char* str, size_t size, const char* format, va_list ap) { diff --git a/tools/bmp2tiff.c b/tools/bmp2tiff.c index ed456b24..797dabdf 100644 --- a/tools/bmp2tiff.c +++ b/tools/bmp2tiff.c @@ -1,4 +1,4 @@ -/* $Id: bmp2tiff.c,v 1.26 2015-06-21 01:09:09 bfriesen Exp $ +/* $Id: bmp2tiff.c,v 1.27 2015-08-19 02:31:04 bfriesen Exp $ * * Project: libtiff tools * Purpose: Convert Windows BMP files in TIFF. @@ -57,6 +57,7 @@ # include "libport.h" #endif +#include "tiffiop.h" #include "tiffio.h" #ifndef O_BINARY @@ -234,7 +235,7 @@ main(int argc, char* argv[]) uint32 rowsperstrip = (uint32) -1; uint16 photometric = PHOTOMETRIC_MINISBLACK; int fd = 0; - struct stat instat; + _TIFF_stat_s instat; char *outfilename = NULL, *infilename = NULL; TIFF *out = NULL; @@ -307,7 +308,7 @@ main(int argc, char* argv[]) /* -------------------------------------------------------------------- */ /* Read the BMPFileHeader. We need iOffBits value only */ /* -------------------------------------------------------------------- */ - if (lseek(fd, 10, SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, 10, SEEK_SET) == (_TIFF_off_t)-1) { TIFFError(infilename, "Failed to seek to offset"); goto bad; } @@ -319,7 +320,7 @@ main(int argc, char* argv[]) #ifdef WORDS_BIGENDIAN TIFFSwabLong(&file_hdr.iOffBits); #endif - if (fstat(fd, &instat) == -1) { + if (_TIFF_fstat_f(fd, &instat) == -1) { TIFFError(infilename, "Failed obtain file information"); goto bad; } @@ -329,7 +330,7 @@ main(int argc, char* argv[]) /* Read the BMPInfoHeader. */ /* -------------------------------------------------------------------- */ - if (lseek(fd, BFH_SIZE, SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, BFH_SIZE, SEEK_SET) == (_TIFF_off_t)-1) { TIFFError(infilename, "Failed to seek to offset"); goto bad; } @@ -479,7 +480,7 @@ main(int argc, char* argv[]) goto bad; } - if (lseek(fd, BFH_SIZE + info_hdr.iSize, SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, BFH_SIZE + info_hdr.iSize, SEEK_SET) == (_TIFF_off_t)-1) { TIFFError(infilename, "Failed to seek to offset"); goto bad; } @@ -613,7 +614,7 @@ main(int argc, char* argv[]) offset = file_hdr.iOffBits+(length-row-1)*size; else offset = file_hdr.iOffBits + row * size; - if (lseek(fd, offset, SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, offset, SEEK_SET) == (_TIFF_off_t)-1) { TIFFError(infilename, "scanline %lu: Seek error", (unsigned long) row); @@ -681,7 +682,7 @@ main(int argc, char* argv[]) goto bad3; } - if (lseek(fd, file_hdr.iOffBits, SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, file_hdr.iOffBits, SEEK_SET) == (_TIFF_off_t)-1) { TIFFError(infilename, "Failed to seek to offset"); goto bad3; } diff --git a/tools/fax2ps.c b/tools/fax2ps.c index 4097e3d9..d565f80c 100644 --- a/tools/fax2ps.c +++ b/tools/fax2ps.c @@ -1,4 +1,4 @@ -/* $Id: fax2ps.c,v 1.29 2015-06-21 01:09:09 bfriesen Exp $" */ +/* $Id: fax2ps.c,v 1.30 2015-08-19 02:31:04 bfriesen Exp $" */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -47,6 +47,7 @@ # include "libport.h" #endif +#include "tiffiop.h" #include "tiffio.h" float defxres = 204.; /* default x resolution (pixels/inch) */ @@ -399,7 +400,7 @@ main(int argc, char** argv) #endif while ((n = read(fileno(stdin), buf, sizeof (buf))) > 0) write(fileno(fd), buf, n); - lseek(fileno(fd), 0, SEEK_SET); + _TIFF_lseek_f(fileno(fd), 0, SEEK_SET); #if defined(_WIN32) && defined(USE_WIN32_FILEIO) tif = TIFFFdOpen(_get_osfhandle(fileno(fd)), "temp", "r"); #else diff --git a/tools/raw2tiff.c b/tools/raw2tiff.c index 5862d9b6..7298e80a 100644 --- a/tools/raw2tiff.c +++ b/tools/raw2tiff.c @@ -1,4 +1,4 @@ -/* $Id: raw2tiff.c,v 1.27 2015-06-21 01:09:10 bfriesen Exp $ +/* $Id: raw2tiff.c,v 1.28 2015-08-19 02:31:04 bfriesen Exp $ * * Project: libtiff tools * Purpose: Convert raw byte sequences in TIFF images @@ -57,6 +57,7 @@ # include "libport.h" #endif +#include "tiffiop.h" #include "tiffio.h" #ifndef HAVE_GETOPT @@ -78,7 +79,7 @@ static int quality = 75; /* JPEG quality */ static uint16 predictor = 0; static void swapBytesInScanline(void *, uint32, TIFFDataType); -static int guessSize(int, TIFFDataType, off_t, uint32, int, +static int guessSize(int, TIFFDataType, _TIFF_off_t, uint32, int, uint32 *, uint32 *); static double correlation(void *, void *, uint32, TIFFDataType); static void usage(void); @@ -89,7 +90,7 @@ main(int argc, char* argv[]) { uint32 width = 0, length = 0, linebytes, bufsize; uint32 nbands = 1; /* number of bands in input image*/ - off_t hdr_size = 0; /* size of the header to skip */ + _TIFF_off_t hdr_size = 0; /* size of the header to skip */ TIFFDataType dtype = TIFF_BYTE; int16 depth = 1; /* bytes per pixel in input image */ int swab = 0; /* byte swapping flag */ @@ -283,14 +284,14 @@ main(int argc, char* argv[]) } TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip ); - lseek(fd, hdr_size, SEEK_SET); /* Skip the file header */ + _TIFF_lseek_f(fd, hdr_size, SEEK_SET); /* Skip the file header */ for (row = 0; row < length; row++) { switch(interleaving) { case BAND: /* band interleaved data */ for (band = 0; band < nbands; band++) { - if (lseek(fd, + if (_TIFF_lseek_f(fd, hdr_size + (length*band+row)*linebytes, - SEEK_SET) == (off_t)-1) { + SEEK_SET) == (_TIFF_off_t)-1) { fprintf(stderr, "%s: %s: scanline %lu: seek error.\n", argv[0], argv[optind], @@ -364,17 +365,17 @@ swapBytesInScanline(void *buf, uint32 width, TIFFDataType dtype) } static int -guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands, +guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands, int swab, uint32 *width, uint32 *length) { const float longt = 40.0; /* maximum possible height/width ratio */ char *buf1, *buf2; - struct stat filestat; + _TIFF_stat_s filestat; uint32 w, h, scanlinesize, imagesize; uint32 depth = TIFFDataWidth(dtype); float cor_coef = 0, tmp; - if (fstat(fd, &filestat) == -1) { + if (_TIFF_fstat_f(fd, &filestat) == -1) { fprintf(stderr, "Failed to obtain file size.\n"); return -1; } @@ -417,8 +418,8 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands, buf2 = _TIFFmalloc(scanlinesize); h = imagesize / w; do { - if (lseek(fd, hdr_size + (int)(h/2)*scanlinesize, - SEEK_SET) == (off_t)-1) { + if (_TIFF_lseek_f(fd, hdr_size + (int)(h/2)*scanlinesize, + SEEK_SET) == (_TIFF_off_t)-1) { fprintf(stderr, "seek error.\n"); fail=1; break; @@ -462,7 +463,7 @@ guessSize(int fd, TIFFDataType dtype, off_t hdr_size, uint32 nbands, return 1; } else { - if (filestat.st_size<(off_t)(hdr_size+(*width)*(*length)*nbands*depth)) { + if (filestat.st_size<(_TIFF_off_t)(hdr_size+(*width)*(*length)*nbands*depth)) { fprintf(stderr, "Input file too small.\n"); return -1; } diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index 0ba9723e..14b16b1c 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -1,4 +1,4 @@ -/* $Id: tiff2pdf.c,v 1.89 2015-06-21 01:09:10 bfriesen Exp $ +/* $Id: tiff2pdf.c,v 1.90 2015-08-19 02:31:04 bfriesen Exp $ * * tiff2pdf - converts a TIFF image to a PDF document * @@ -412,7 +412,7 @@ t2p_seekproc(thandle_t handle, uint64 offset, int whence) { T2P *t2p = (T2P*) handle; if (t2p->outputdisable <= 0 && t2p->outputfile) - return fseek(t2p->outputfile, (long) offset, whence); + return _TIFF_fseek_f(t2p->outputfile, (_TIFF_off_t) offset, whence); return offset; } diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c index c2732ec6..b5a49cc2 100644 --- a/tools/tiffcrop.c +++ b/tools/tiffcrop.c @@ -1,4 +1,4 @@ -/* $Id: tiffcrop.c,v 1.34 2015-06-21 01:09:10 bfriesen Exp $ */ +/* $Id: tiffcrop.c,v 1.35 2015-08-19 02:31:04 bfriesen Exp $ */ /* tiffcrop.c -- a port of tiffcp.c extended to include manipulations of * the image data through additional options listed below @@ -131,7 +131,7 @@ static char tiffcrop_rev_date[] = "12-13-2010"; #endif #ifndef HAVE_GETOPT -extern int getopt(int, char**, char*); +extern int getopt(int argc, char * const argv[], const char *optstring); #endif #ifdef NEED_LIBPORT diff --git a/tools/tiffdump.c b/tools/tiffdump.c index a5481260..7aa1c178 100644 --- a/tools/tiffdump.c +++ b/tools/tiffdump.c @@ -1,4 +1,4 @@ -/* $Id: tiffdump.c,v 1.31 2015-06-21 01:09:11 bfriesen Exp $ */ +/* $Id: tiffdump.c,v 1.32 2015-08-19 02:31:05 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -171,7 +171,7 @@ dump(int fd, uint64 diroff) uint64* visited_diroff = NULL; unsigned int count_visited_dir = 0; - lseek(fd, (off_t) 0, 0); + _TIFF_lseek_f(fd, (_TIFF_off_t) 0, 0); if (read(fd, (char*) &hdr, sizeof (TIFFHeaderCommon)) != sizeof (TIFFHeaderCommon)) ReadError("TIFF header"); if (hdr.common.tiff_magic != TIFF_BIGENDIAN @@ -309,11 +309,7 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) if (off == 0) /* no more directories */ goto done; -#if defined(__WIN32__) && defined(_MSC_VER) - if (_lseeki64(fd, (__int64)off, SEEK_SET) != (__int64)off) { -#else - if (lseek(fd, (off_t)off, SEEK_SET) != (off_t)off) { -#endif + if (_TIFF_lseek_f(fd, (_TIFF_off_t)off, SEEK_SET) != (_TIFF_off_t)off) { Fatal("Seek error accessing TIFF directory"); goto done; } @@ -479,13 +475,8 @@ ReadDirectory(int fd, unsigned int ix, uint64 off) { datamem = _TIFFmalloc((uint32)datasize); if (datamem) { -#if defined(__WIN32__) && defined(_MSC_VER) - if (_lseeki64(fd, (__int64)dataoffset, SEEK_SET) - != (__int64)dataoffset) -#else - if (lseek(fd, (off_t)dataoffset, 0) != - (off_t)dataoffset) -#endif + if (_TIFF_lseek_f(fd, (_TIFF_off_t)dataoffset, 0) != + (_TIFF_off_t)dataoffset) { Error( "Seek error accessing tag %u value", tag);