31#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
32#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
125 if ((uint64_t)n > mb)
127 if (!ReadFile(fd, (LPVOID)ma, n, &o, NULL))
171 if ((uint64_t)n > mb)
173 if (!WriteFile(fd, (LPVOID)ma, n, &o, NULL))
203 offli.QuadPart = (LONGLONG)off;
207 dwMoveMethod = FILE_BEGIN;
210 dwMoveMethod = FILE_CURRENT;
213 dwMoveMethod = FILE_END;
216 dwMoveMethod = FILE_BEGIN;
220 SetFilePointer(fd, (LONG)offli.LowPart, &offli.HighPart, dwMoveMethod);
221 if ((offli.LowPart == INVALID_SET_FILE_POINTER) &&
222 (GetLastError() != NO_ERROR))
223 return ((uint64_t)-1);
224 return ((uint64_t)offli.QuadPart);
254 if (GetFileSizeEx(fd, &m))
255 return ((uint64_t)m.QuadPart);
298 if (!size || (uint64_t)sizem != size)
303 hMapFile = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL);
304 if (hMapFile == NULL)
306 *pbase = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
307 CloseHandle(hMapFile);
330 UnmapViewOfFile(base);
351 for (m = 0; mode[m] != 0; m++)
382 static const char module[] = "TIFFOpen";
393 dwMode = OPEN_EXISTING;
396 dwMode = OPEN_EXISTING;
398 case O_RDWR | O_CREAT:
399 dwMode = OPEN_ALWAYS;
401 case O_RDWR | O_TRUNC:
402 dwMode = CREATE_ALWAYS;
404 case O_RDWR | O_CREAT | O_TRUNC:
405 dwMode = CREATE_ALWAYS;
412 name, (m == O_RDONLY) ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE),
413 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode,
414 (m == O_RDONLY) ? FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL,
416 if (fd == INVALID_HANDLE_VALUE)
499 static const char module[] = "TIFFOpenW";
512 dwMode = OPEN_EXISTING;
515 dwMode = OPEN_EXISTING;
517 case O_RDWR | O_CREAT:
518 dwMode = OPEN_ALWAYS;
520 case O_RDWR | O_TRUNC:
521 dwMode = CREATE_ALWAYS;
523 case O_RDWR | O_CREAT | O_TRUNC:
524 dwMode = CREATE_ALWAYS;
531 name, (m == O_RDONLY) ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE),
532 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode,
533 (m == O_RDONLY) ? FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL,
535 if (fd == INVALID_HANDLE_VALUE)
542 mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
550 "Can't allocate space for filename conversion buffer");
554 WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, NULL, NULL);
558 (mbname != NULL) ? mbname :
"<unknown>", mode, opts);
572 return ((
void *)NULL);
574 return (malloc((
size_t)s));
579 if (nmemb == 0 || siz == 0)
580 return ((
void *)NULL);
582 return calloc((
size_t)nmemb, (
size_t)siz);
593 memcpy(d, s, (
size_t)c);
598 return (memcmp(p1, p2, (
size_t)c));
620 fprintf(stderr,
"%s: ", module);
621 fprintf(stderr,
"Warning, ");
622 vfprintf(stderr, fmt, ap);
623 fprintf(stderr,
".\n");
643 fprintf(stderr,
"%s: ", module);
644 vfprintf(stderr, fmt, ap);
645 fprintf(stderr,
".\n");
static void Win32WarningHandler(const char *module, const char *fmt, va_list ap)
Print a default warning diagnostic to stderr.
TIFFErrorHandler _TIFFwarningHandler
Store the global warning callback.
static void Win32ErrorHandler(const char *module, const char *fmt, va_list ap)
Print a default error diagnostic to stderr.
TIFFErrorHandler _TIFFerrorHandler
Store the global error callback.
static int thandle_to_int(thandle_t fd)
Convert a native Windows handle to the backend integer representation.
static thandle_t thandle_from_int(int ifd)
Convert the native Windows integer handle representation to thandle_t.
int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Decline mapping when the client supplies no mapping implementation.
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.
void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Provide a no-op unmapper when the client omits one.
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 ifd, 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 ifd, 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.
static tmsize_t _tiffReadProc(thandle_t fd, void *buf, tmsize_t size)
Read bytes from the Windows HANDLE with ReadFile().
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 Windows HANDLE with WriteFile().
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.
static int _tiffMapProc(thandle_t fd, void **pbase, toff_t *psize)
Create a read-only view of the entire backend resource.
Declare private library state, callbacks, and implementation helpers.