LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Modules | Data Structures | Macros | Typedefs | Functions
Lifecycle internals

Support initialisation, resource callbacks, and handle cleanup. More...

Collaboration diagram for Lifecycle internals:

Modules

 C++ stream adapters
 Track borrowed streams and implement their client I/O callbacks.
 

Data Structures

union  fd_as_handle_union
 Carry descriptor bits through the opaque client-handle representation. More...
 

Macros

#define TIFF_IO_MAX   2147483647U
 Limit one descriptor read/write request to 2147483647 bytes.
 

Typedefs

typedef union fd_as_handle_union fd_as_handle_union_t
 Carry descriptor bits through the opaque client-handle representation.
 

Functions

static tmsize_t _tiffReadProc (thandle_t fd, void *buf, tmsize_t size)
 Read bytes from the descriptor with read().
 
static tmsize_t _tiffWriteProc (thandle_t fd, void *buf, tmsize_t size)
 Write bytes to the descriptor with write().
 
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.
 
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.
 
int _tiffDummyMapProc (thandle_t fd, void **pbase, toff_t *psize)
 Decline mapping when the client supplies no mapping implementation.
 
void _tiffDummyUnmapProc (thandle_t fd, void *base, toff_t size)
 Provide a no-op unmapper when the client omits one.
 
int _TIFFgetMode (TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
 Translate the leading open-mode characters into OS access flags.
 
void _TIFFErrorEarly (TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
 Report an opening error before a complete TIFF handle is available.
 
void _TIFFCleanupIFDOffsetAndNumberMaps (TIFF *tif)
 Release a handle's directory-offset/index lookup maps.
 

Detailed Description

Support initialisation, resource callbacks, and handle cleanup.

Macro Definition Documentation

◆ TIFF_IO_MAX

#define TIFF_IO_MAX   2147483647U

Limit one descriptor read/write request to 2147483647 bytes.

Definition at line 68 of file tif_unix.c.

Typedef Documentation

◆ fd_as_handle_union_t

Carry descriptor bits through the opaque client-handle representation.

Used only by the descriptor backend; the union does not own a resource.

Function Documentation

◆ _TIFFCleanupIFDOffsetAndNumberMaps()

void _TIFFCleanupIFDOffsetAndNumberMaps ( TIFF *  tif)
extern

Release a handle's directory-offset/index lookup maps.

Destroys each existing map and sets its member pointer to NULL. Borrowed entries/views into the maps become invalid. Does not free the TIFF handle or close client I/O and has no status result or direct diagnostic.

Parameters
[in,out]tifNon-NULL TIFF handle whose maps may be NULL.

Definition at line 127 of file tif_close.c.

References tiff::tif_map_dir_number_to_offset, tiff::tif_map_dir_offset_to_number, and TIFFHashSetDestroy().

Referenced by TIFFCleanup(), TIFFCreateCustomDirectory(), TIFFSetDirectory(), TIFFSetSubDirectory(), and TIFFUnlinkDirectory().

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

◆ _tiffCloseProc()

static int _tiffCloseProc ( thandle_t  fd)
static

Release the backend OS resource.

Calls close() and forwards its status/errno without retry or library diagnostics. Resource state after a failed close follows the platform close contract; a successful close invalidates the descriptor.

Parameters
[in,out]fdLive file descriptor carried by fd_as_handle_union_t.
Returns
Zero on success and -1 on failure.

Definition at line 223 of file tif_unix.c.

References fd_as_handle_union::fd, and fd_as_handle_union::h.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffDummyMapProc()

int _tiffDummyMapProc ( thandle_t  fd,
void **  pbase,
toff_t *  psize 
)
extern

Decline mapping when the client supplies no mapping implementation.

Allocates nothing, performs no I/O, and emits no diagnostic. The unchanged outputs must not be used as a mapped view.

Parameters
[in]fdUnused client context.
[out]pbaseUnused view-base output; left unchanged.
[out]psizeUnused size output; left unchanged.
Returns
Zero, indicating no mapping is available.

Definition at line 45 of file tif_open.c.

Referenced by TIFFClientOpenExt(), and TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _tiffDummyUnmapProc()

void _tiffDummyUnmapProc ( thandle_t  fd,
void *  base,
toff_t  size 
)
extern

Provide a no-op unmapper when the client omits one.

Does not release storage, perform I/O, or emit diagnostics. Returns no status; pairing this with a real mapper is safe only if the view needs no explicit release.

Parameters
[in]fdUnused client context.
[in]baseUnused view base.
[in]sizeUnused byte length.

Definition at line 53 of file tif_open.c.

Referenced by TIFFClientOpenExt(), and TIFFFdOpenExt().

Here is the caller graph for this function:

◆ _TIFFErrorEarly()

void _TIFFErrorEarly ( TIFFOpenOptions *  opts,
thandle_t  clientdata,
const char *  module,
const char *  fmt,
  ... 
)

Report an opening error before a complete TIFF handle is available.

Invokes opts->errorhandler, if present, with tif = NULL and the borrowed error context. A nonzero callback result suppresses the legacy global handlers for this message; otherwise the global ordinary and extended handlers run if installed. The extended handler receives clientdata. Returns no status and does not itself abort opening or own any argument storage. Callback effects and exceptions are not rolled back.

Parameters
[in]optsOptional borrowed open options containing a per-handle error callback.
[in]clientdataOpaque context supplied to the legacy extended handler.
[in]moduleBorrowed diagnostic module name, possibly NULL.
[in]fmtNon-NULL printf-style format string.
[in]...Arguments matching the format string and default variadic promotions.

Definition at line 85 of file tif_error.c.

References _TIFFerrorHandler, _TIFFerrorHandlerExt, TIFFOpenOptions::errorhandler, and TIFFOpenOptions::errorhandler_user_data.

Referenced by _TIFFgetMode(), TIFFClientOpenExt(), TIFFOpenExt(), and TIFFOpenWExt().

Here is the caller graph for this function:

◆ _TIFFgetMode()

int _TIFFgetMode ( TIFFOpenOptions *  opts,
thandle_t  clientdata,
const char *  mode,
const char *  module 
)
extern

Translate the leading open-mode characters into OS access flags.

Inspects only the first character and an immediately following + after r; library modifiers are processed later. An invalid first character emits _TIFFErrorEarly() and returns -1. Does not open, close, allocate, or take ownership of a resource. Callback contexts remain borrowed.

Parameters
[in]optsOptional borrowed settings for early error reporting.
[in]clientdataClient context passed to legacy extended early- error handling.
[in]modeNon-NULL null-terminated mode string.
[in]moduleBorrowed diagnostic module name.
Returns
O_RDONLY for r, O_RDWR for r+ immediately following r, or O_RDWR | O_CREAT with O_TRUNC added for w; a selects O_RDWR | O_CREAT. Returns -1 for any other first character.

Definition at line 60 of file tif_open.c.

References _TIFFErrorEarly().

Referenced by TIFFClientOpenExt(), TIFFOpenExt(), and TIFFOpenWExt().

Here is the call graph for this function:
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 the length with _tiffSizeProc() and calls mmap(PROT_READ, MAP_SHARED). If mmap() fails, *pbase is left holding MAP_FAILED; earlier failures leave it unchanged. A successful view must be released through _tiffUnmapProc(), not an allocator. errno follows attempted platform operations; no library diagnostic is emitted.

Parameters
[in]fdLive file descriptor carried by fd_as_handle_union_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 an mmap() failure, an empty file or failed size query, or a length not representable as tmsize_t.

Definition at line 273 of file tif_unix.c.

References _tiffSizeProc(), fd_as_handle_union::fd, and fd_as_handle_union::h.

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 descriptor with read().

Loops over chunks limited by TIFF_IO_MAX until the request completes, read() returns zero (end of file), or read() fails. Does not retry EINTR. A -1 result can follow earlier successful chunks, so the file position and the destination bytes may already have changed. errno follows read(); a size that does not survive conversion to size_t sets EINVAL. Does not issue a library diagnostic or take buffer ownership.

Parameters
[in,out]fdLive file descriptor carried by fd_as_handle_union_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, which is less than size at end of file, or -1 if a read() call fails. A zero size also returns -1.

Definition at line 102 of file tif_unix.c.

References fd_as_handle_union::fd, fd_as_handle_union::h, and TIFF_IO_MAX.

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.

Converts to _TIFF_off_t and checks the unsigned round trip, then calls _TIFF_lseek_f. A failed conversion sets EINVAL without seeking. Other errors follow the platform call and errno. Does not emit library diagnostics or transfer ownership.

Parameters
[in,out]fdLive file descriptor carried by fd_as_handle_union_t.
[in]offByte offset converted to the platform signed offset type.
[in]whenceSeek origin requested by the library.
Returns
The resulting byte position, or UINT64_MAX for a -1 result or a failed offset conversion.

Definition at line 199 of file tif_unix.c.

References _TIFF_lseek_f, _TIFF_off_t, fd_as_handle_union::fd, and fd_as_handle_union::h.

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 _TIFF_fstat_f() without seeking. errno follows OS failure. Does not transfer ownership or emit library diagnostics.

Parameters
[in]fdLive file descriptor carried by fd_as_handle_union_t.
Returns
The byte length, or zero on query failure; an empty file also has length zero.

Definition at line 241 of file tif_unix.c.

References _TIFF_fstat_f, _TIFF_stat_s, fd_as_handle_union::fd, and fd_as_handle_union::h.

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 munmap() and discards its result. A released view is invalid. Failure has no callback status or library diagnostic and does not close the file descriptor.

Parameters
[in]fdUnused client context.
[in]baseMapped-view base, or NULL during early failed-open cleanup.
[in]sizeMapped length in bytes.

Definition at line 304 of file tif_unix.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 descriptor with write().

Loops over chunks limited by TIFF_IO_MAX until the request completes, write() returns zero, or write() fails. Does not retry EINTR. A -1 result can follow earlier successful chunks, so the file position and contents may already have changed. errno follows write(); a size that does not survive conversion to size_t sets EINVAL. Does not issue a library diagnostic or take buffer ownership.

Parameters
[in,out]fdLive file descriptor carried by fd_as_handle_union_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, which is less than size if write() returned zero, or -1 if a write() call fails. A zero size also returns -1.

Definition at line 151 of file tif_unix.c.

References fd_as_handle_union::fd, fd_as_handle_union::h, and TIFF_IO_MAX.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ thandle_from_int()

static thandle_t thandle_from_int ( int  ifd)
inlinestatic

Convert the native Windows integer handle representation to thandle_t.

Performs no OS validation, allocation, close, or diagnostic. Does not transfer ownership.

Parameters
[in]ifdInteger representation of a Windows HANDLE, not a CRT descriptor.
Returns
The handle value cast through intptr_t.

Definition at line 74 of file tif_win32.c.

Referenced by TIFFFdOpenExt().

Here is the caller graph for this function:

◆ thandle_to_int()

static int thandle_to_int ( thandle_t  fd)
inlinestatic

Convert a native Windows handle to the backend integer representation.

Performs no OS validation, allocation, close, or diagnostic. Does not transfer ownership; this is the backend HANDLE convention, not a CRT- descriptor conversion.

Parameters
[in]fdNative Windows HANDLE represented as thandle_t.
Returns
The integer representation produced through intptr_t.

Definition at line 90 of file tif_win32.c.

Referenced by TIFFOpenExt(), and TIFFOpenWExt().

Here is the caller graph for this function: