LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Functions | Variables
tif_win32.c File Reference

Implement native Windows resource callbacks and pathname opening. More...

#include "tiffiop.h"
#include <stdlib.h>
#include <windows.h>
Include dependency graph for tif_win32.c:

Go to the source code of this file.

Functions

static thandle_t thandle_from_int (int ifd)
 Convert the native Windows integer handle representation to thandle_t.
 
static int thandle_to_int (thandle_t fd)
 Convert a native Windows handle to the backend integer representation.
 
static tmsize_t _tiffReadProc (thandle_t fd, void *buf, tmsize_t size)
 Read bytes from the Windows HANDLE with ReadFile().
 
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.
 
static void _tiffUnmapProc (thandle_t fd, void *base, toff_t size)
 Release a read-only backend mapping.
 
TIFF * TIFFFdOpen (int ifd, const char *name, const char *mode)
 Attach a TIFF handle to an already-open platform resource.
 
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 * TIFFOpenExt (const char *name, const char *mode, TIFFOpenOptions *opts)
 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 * TIFFOpenWExt (const wchar_t *name, const char *mode, TIFFOpenOptions *opts)
 Open a TIFF file using a wide Windows pathname.
 
void * _TIFFmalloc (tmsize_t s)
 Allocate an uninitialised block through the public allocator.
 
void * _TIFFcalloc (tmsize_t nmemb, tmsize_t siz)
 Allocate a zero-filled array through the public allocator.
 
void _TIFFfree (void *p)
 Release a block allocated by the public allocation family.
 
void * _TIFFrealloc (void *p, tmsize_t s)
 Resize a public-allocator block using platform realloc semantics.
 
void _TIFFmemset (void *p, int v, tmsize_t c)
 Fill a byte range with one repeated byte.
 
void _TIFFmemcpy (void *d, const void *s, tmsize_t c)
 Copy a non-overlapping byte range.
 
int _TIFFmemcmp (const void *p1, const void *p2, tmsize_t c)
 Compare two byte ranges lexicographically.
 
static void Win32WarningHandler (const char *module, const char *fmt, va_list ap)
 Print a default warning diagnostic to stderr.
 
static void Win32ErrorHandler (const char *module, const char *fmt, va_list ap)
 Print a default error diagnostic to stderr.
 

Variables

TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler
 Store the global warning callback.
 
TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler
 Store the global error callback.
 

Detailed Description

Implement native Windows resource callbacks and pathname opening.

Definition in file tif_win32.c.

Function Documentation

◆ _tiffCloseProc()

static int _tiffCloseProc ( thandle_t  fd)
static

Release the backend OS resource.

Calls CloseHandle(). Its result is translated to the callback convention; GetLastError() describes OS failure. No library diagnostic is added. The handle is invalid after successful close.

Parameters
[in,out]fdLive native Windows HANDLE encoded as thandle_t.
Returns
Zero on success and -1 on failure.

Definition at line 238 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffMapProc()

static int _tiffMapProc ( thandle_t  fd,
void **  pbase,
toff_t *  psize 
)
static

Create a read-only view of the entire backend resource.

Queries file size and maps the whole resource. The view must be released through _tiffUnmapProc(), not an allocator. The temporary Windows file- mapping HANDLE is closed after MapViewOfFile(), while the view remains valid. API failure may set *pbase to NULL; earlier failures leave it unchanged. No library diagnostic is emitted.

Parameters
[in]fdLive native Windows HANDLE encoded as thandle_t.
[out]pbaseOutput view base on success; do not rely on it after failure.
[out]psizeOutput view length in bytes on success; unchanged on failure.
Returns
1 for a mapped view; 0 for a CreateFileMapping() or MapViewOfFile() failure, an empty file or failed size query, or a length not representable as tmsize_t.

Definition at line 290 of file tif_win32.c.

References _tiffSizeProc().

Referenced by TIFFFdOpenExt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _tiffReadProc()

static tmsize_t _tiffReadProc ( thandle_t  fd,
void *  buf,
tmsize_t  size 
)
static

Read bytes from the Windows HANDLE with ReadFile().

Reads in chunks no larger than 0x80000000 bytes and stops at a short read. Zero length returns zero. API errors are exposed through the Windows last-error state; there is no library diagnostic here. The file position and destination bytes may already have changed before failure. Buffer ownership is unchanged.

Parameters
[in,out]fdLive native Windows HANDLE encoded as thandle_t.
[out]bufWritable destination of at least size bytes.
[in]sizeNonnegative byte request representable by tmsize_t and the backend.
Returns
The number of bytes read (less than size at end of file), or zero on any ReadFile() failure even if earlier chunks transferred data.

Definition at line 109 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffSeekProc()

static uint64_t _tiffSeekProc ( thandle_t  fd,
uint64_t  off,
int  whence 
)
static

Seek the platform resource and return its reported position.

Uses SetFilePointer; unsupported origins fall back to FILE_BEGIN. Failure is detected through GetLastError() and reported as (uint64_t)-1. Position preservation on failure is not guaranteed, and no library diagnostic is emitted.

Parameters
[in,out]fdLive native Windows HANDLE encoded as thandle_t.
[in]offByte offset, reinterpreted as a signed LONGLONG.
[in]whenceSEEK_SET, SEEK_CUR or SEEK_END; any other value is treated as SEEK_SET.
Returns
The Windows position, or (uint64_t)-1 on SetFilePointer failure.

Definition at line 199 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffSizeProc()

static uint64_t _tiffSizeProc ( thandle_t  fd)
static

Query the backend resource length in bytes.

Uses GetFileSizeEx() without seeking. GetLastError() follows OS failure. Does not transfer ownership or emit library diagnostics.

Parameters
[in]fdLive native Windows HANDLE encoded as thandle_t.
Returns
The byte length, or zero on query failure; an empty file also has length zero.

Definition at line 251 of file tif_win32.c.

Referenced by _tiffMapProc(), and TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffUnmapProc()

static void _tiffUnmapProc ( thandle_t  fd,
void *  base,
toff_t  size 
)
static

Release a read-only backend mapping.

Calls UnmapViewOfFile() and discards its result. The view must no longer be used after successful unmapping; failures have no callback status or library diagnostic. Does not close the file HANDLE.

Parameters
[in]fdUnused client context.
[in]baseMapped-view base, or NULL during early failed-open cleanup.
[in]sizeMapped length in bytes; unused by the Windows API.

Definition at line 326 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffWriteProc()

static tmsize_t _tiffWriteProc ( thandle_t  fd,
void *  buf,
tmsize_t  size 
)
static

Write bytes to the Windows HANDLE with WriteFile().

Writes in chunks no larger than 0x80000000 bytes and stops at a short write. Zero length returns zero. API errors are exposed through the Windows last-error state; there is no library diagnostic here. The file position and contents may already have changed before failure. Buffer ownership is unchanged.

Parameters
[in,out]fdLive native Windows HANDLE encoded as thandle_t.
[in]bufReadable source of at least size bytes.
[in]sizeNonnegative byte request representable by tmsize_t and the backend.
Returns
The number of bytes written (less than size after a short write), or zero on any WriteFile() failure even if earlier chunks transferred data.

Definition at line 155 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function: