LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_bytecursor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026, Guillermo Hernandez
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
37#ifndef TIF_BYTECURSOR_H
38#define TIF_BYTECURSOR_H
39
40#include "tiffiop.h"
41
50typedef struct
51{
53 uint8_t *p;
57
70static inline int _TIFFByteCursorGetU8(TIFFByteCursor *c, uint8_t *out)
71{
72 if (c->left <= 0)
73 return 0;
74 *out = *c->p++;
75 c->left--;
76 return 1;
77}
78
91static inline int _TIFFByteCursorFill(TIFFByteCursor *dst, uint8_t value,
92 tmsize_t n)
93{
94 if (n < 0 || n > dst->left)
95 return 0;
96 _TIFFmemset(dst->p, value, n);
97 dst->p += n;
98 dst->left -= n;
99 return 1;
100}
101
116 tmsize_t n)
117{
118 if (n < 0 || n > dst->left || n > src->left)
119 return 0;
120 _TIFFmemcpy(dst->p, src->p, n);
121 dst->p += n;
122 dst->left -= n;
123 src->p += n;
124 src->left -= n;
125 return 1;
126}
127
128#endif /* TIF_BYTECURSOR_H */
static int _TIFFByteCursorFill(TIFFByteCursor *dst, uint8_t value, tmsize_t n)
Write n copies of value to a cursor.
static int _TIFFByteCursorCopy(TIFFByteCursor *dst, TIFFByteCursor *src, tmsize_t n)
Move n bytes from src to dst.
static int _TIFFByteCursorGetU8(TIFFByteCursor *c, uint8_t *out)
Read one byte from a cursor.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
Definition tif_unix.c:495
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Definition tif_unix.c:497
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
Track a borrowed byte range as a pointer and a remaining count.
tmsize_t left
Number of bytes remaining from p.
uint8_t * p
Next byte to read or write.
Declare private library state, callbacks, and implementation helpers.