File Coverage

include/pdfmake_internal.h
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 3 3 100.0


line stmt bran cond sub pod time code
1             /*
2             * pdfmake_internal.h — private cross-module helpers.
3             *
4             * NOT part of the public API. Do not install. Callers are restricted to
5             * translation units under src/ in this library. The intent is a single place
6             * for small `static PDFMAKE_INLINE` utilities and macros that are shared by two or
7             * more .c files but too trivial to deserve their own module header.
8             *
9             * Rules for additions:
10             * - Two or more callers, identical semantics. One-shot helpers stay
11             * file-local.
12             * - `static PDFMAKE_INLINE` whenever possible — this header is included from
13             * multiple TUs, so non-inline definitions would multiply-define.
14             * - No allocation. No global state. Leaf functions only.
15             * - Zero dependencies beyond , , .
16             */
17              
18             #ifndef PDFMAKE_INTERNAL_H
19             #define PDFMAKE_INTERNAL_H
20              
21             #include "pdfmake_types.h"
22              
23             #include
24             #include
25              
26             #ifdef __cplusplus
27             extern "C" {
28             #endif
29              
30             /*----------------------------------------------------------------------------
31             * Big-endian byte readers / writers.
32             *
33             * Every binary parser in the library (TTF, CFF, PNG, SHA-2, ASN.1 length
34             * fields, xref streams, etc.) needs to pull multi-byte integers out of a
35             * byte buffer in network/big-endian order. Rather than redefining the
36             * same 3-line helpers in each .c file (we had five near-identical
37             * copies pre-Phase-4), they live here.
38             *---------------------------------------------------------------------------*/
39              
40             static PDFMAKE_INLINE uint16_t pdfmake_read_be16(const uint8_t *p) {
41             return ((uint16_t)p[0] << 8) | p[1];
42             }
43              
44             static PDFMAKE_INLINE int16_t pdfmake_read_sbe16(const uint8_t *p) {
45             return (int16_t)pdfmake_read_be16(p);
46             }
47              
48 135           static PDFMAKE_INLINE uint32_t pdfmake_read_be32(const uint8_t *p) {
49 135           return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) |
50 135           ((uint32_t)p[2] << 8) | (uint32_t)p[3];
51             }
52              
53             static PDFMAKE_INLINE uint64_t pdfmake_read_be64(const uint8_t *p) {
54             return ((uint64_t)p[0] << 56) | ((uint64_t)p[1] << 48) |
55             ((uint64_t)p[2] << 40) | ((uint64_t)p[3] << 32) |
56             ((uint64_t)p[4] << 24) | ((uint64_t)p[5] << 16) |
57             ((uint64_t)p[6] << 8) | (uint64_t)p[7];
58             }
59              
60             static PDFMAKE_INLINE void pdfmake_write_be16(uint8_t *p, uint16_t x) {
61             p[0] = (uint8_t)(x >> 8);
62             p[1] = (uint8_t)(x);
63             }
64              
65             static PDFMAKE_INLINE void pdfmake_write_be32(uint8_t *p, uint32_t x) {
66             p[0] = (uint8_t)(x >> 24);
67             p[1] = (uint8_t)(x >> 16);
68             p[2] = (uint8_t)(x >> 8);
69             p[3] = (uint8_t)(x);
70             }
71              
72             static PDFMAKE_INLINE void pdfmake_write_be64(uint8_t *p, uint64_t x) {
73             p[0] = (uint8_t)(x >> 56);
74             p[1] = (uint8_t)(x >> 48);
75             p[2] = (uint8_t)(x >> 40);
76             p[3] = (uint8_t)(x >> 32);
77             p[4] = (uint8_t)(x >> 24);
78             p[5] = (uint8_t)(x >> 16);
79             p[6] = (uint8_t)(x >> 8);
80             p[7] = (uint8_t)(x);
81             }
82              
83             #ifdef __cplusplus
84             }
85             #endif
86              
87             #endif /* PDFMAKE_INTERNAL_H */