30#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
31#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
41#ifdef HAVE_SYS_TYPES_H
68#define TIFF_IO_MAX 2147483647U
105 const size_t bytes_total = (size_t)size;
114 for (bytes_read = 0; bytes_read < bytes_total; bytes_read += (size_t)count)
116 char *buf_offset = (
char *)buf + bytes_read;
117 size_t io_size = (size_t)(bytes_total - bytes_read);
154 const size_t bytes_total = (size_t)size;
155 size_t bytes_written;
163 for (bytes_written = 0; bytes_written < bytes_total;
164 bytes_written += (size_t)count)
166 const char *buf_offset = (
char *)buf + bytes_written;
167 size_t io_size = (size_t)(bytes_total - bytes_written);
203 if ((uint64_t)off_io != off)
227 return (close(fdh.
fd));
249 return ((uint64_t)sb.st_size);
277 if (size64 && (uint64_t)sizem == size64)
282 (
void *)mmap(0, (
size_t)sizem, PROT_READ, MAP_SHARED, fdh.
fd, 0);
283 if (*pbase != (
void *)-1)
307 (void)munmap(base, (
size_t)size);
381 static const char module[] = "TIFFOpen";
394 fd = open(name, m, 0666);
397 if (errno > 0 && strerror(errno) != NULL)
426 static const char module[] = "TIFFOpenW";
441 fd = _wopen(name, m, 0666);
449 mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
457 "Can't allocate space for filename conversion buffer");
461 WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, NULL, NULL);
464 tif =
TIFFFdOpenExt((
int)fd, (mbname != NULL) ? mbname :
"<unknown>", mode,
478 return ((
void *)NULL);
480 return (malloc((
size_t)s));
485 if (nmemb == 0 || siz == 0)
486 return ((
void *)NULL);
488 return calloc((
size_t)nmemb, (
size_t)siz);
499 memcpy(d, s, (
size_t)c);
504 return (memcmp(p1, p2, (
size_t)c));
525 fprintf(stderr,
"%s: ", module);
526 fprintf(stderr,
"Warning, ");
527 vfprintf(stderr, fmt, ap);
528 fprintf(stderr,
".\n");
549 fprintf(stderr,
"%s: ", module);
550 vfprintf(stderr, fmt, ap);
551 fprintf(stderr,
".\n");
static void unixErrorHandler(const char *module, const char *fmt, va_list ap)
Print a default error diagnostic to stderr.
TIFFErrorHandler _TIFFwarningHandler
Store the global warning callback.
static void unixWarningHandler(const char *module, const char *fmt, va_list ap)
Print a default warning diagnostic to stderr.
TIFFErrorHandler _TIFFerrorHandler
Store the global error callback.
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Read bytes from the descriptor with read().
union fd_as_handle_union fd_as_handle_union_t
Carry descriptor bits through the opaque client-handle representation.
static void _tiffUnmapProc(thandle_t fd, void *base, toff_t size)
Release a read-only backend mapping.
static tmsize_t _tiffWriteProc(thandle_t fd, void *buf, tmsize_t size)
Write bytes to the descriptor with write().
void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
Report an opening error before a complete TIFF handle is available.
int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
Translate the leading open-mode characters into OS access flags.
static uint64_t _tiffSeekProc(thandle_t fd, uint64_t off, int whence)
Seek the platform resource and return its reported position.
static int _tiffCloseProc(thandle_t fd)
Release the backend OS resource.
static uint64_t _tiffSizeProc(thandle_t fd)
Query the backend resource length in bytes.
#define TIFF_IO_MAX
Limit one descriptor read/write request to 2147483647 bytes.
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Create a read-only view of the entire backend resource.
#define _TIFF_fstat_f(fildes, stat_buff)
Query file status through the platform large-file interface.
#define _TIFF_stat_s
Select the platform file-status structure type.
#define _TIFF_lseek_f(fildes, offset, whence)
Seek a file descriptor through the platform large-file interface.
size_t TIFFIOSize_t
Represent a native POSIX I/O byte count.
#define _TIFF_off_t
Select the platform large-file offset type.
#define TIFF_ATTRIBUTE(x)
Expand a compiler attribute in a public declaration when supported.
void(* TIFFErrorHandler)(const char *module, const char *fmt, va_list ap)
Handle a library-wide error or warning diagnostic.
TIFF * TIFFClientOpenExt(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc, TIFFOpenOptions *opts)
Initialise a TIFF handle using client-supplied I/O callbacks.
TIFF * TIFFOpenExt(const char *name, const char *mode, TIFFOpenOptions *opts)
Open a TIFF file by pathname.
TIFF * TIFFFdOpenExt(int fd, const char *name, const char *mode, TIFFOpenOptions *opts)
Attach a TIFF handle to an already-open platform resource.
TIFF * TIFFOpen(const char *name, const char *mode)
Open a TIFF file by pathname.
TIFF * TIFFOpenW(const wchar_t *name, const char *mode)
Open a TIFF file using a wide Windows pathname.
TIFF * TIFFFdOpen(int fd, const char *name, const char *mode)
Attach a TIFF handle to an already-open platform resource.
TIFF * TIFFOpenWExt(const wchar_t *name, const char *mode, TIFFOpenOptions *opts)
Open a TIFF file using a wide Windows pathname.
void _TIFFfree(void *p)
Release a block allocated by the public allocation family.
void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array through the public allocator.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
void * _TIFFmalloc(tmsize_t s)
Allocate an uninitialised block through the public allocator.
int _TIFFmemcmp(const void *p1, const void *p2, tmsize_t c)
Compare two byte ranges lexicographically.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
void * _TIFFrealloc(void *p, tmsize_t s)
Resize a public-allocator block using platform realloc semantics.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
void * thandle_t
Carry an opaque client I/O context through library callbacks.
Hold allocation limits and diagnostics used when opening a TIFF handle.
Hold private state for one open TIFF library instance.
int tif_fd
File-descriptor metadata; client I/O still uses tif_clientdata.
Define private build features, platform probes, and formatting helpers.
Declare private library state, callbacks, and implementation helpers.
Carry descriptor bits through the opaque client-handle representation.
thandle_t h
Opaque callback-context view of the stored bits.
int fd
Descriptor view of the stored bits.