Rizin
unix-like reverse engineering framework and cli tools
tuklib_integer.h File Reference

Various integer and bit operations. More...

#include "tuklib_common.h"
#include <string.h>

Go to the source code of this file.

Macros

#define bswap16(n)
 
#define bswap32(n)
 
#define bswap64(n)
 
#define conv16be(num)   bswap16(num)
 
#define conv32be(num)   bswap32(num)
 
#define conv64be(num)   bswap64(num)
 
#define conv16le(num)   ((uint16_t)(num))
 
#define conv32le(num)   ((uint32_t)(num))
 
#define conv64le(num)   ((uint64_t)(num))
 
#define write16le(buf, num)   write16ne(buf, conv16le(num))
 
#define write32le(buf, num)   write32ne(buf, conv32le(num))
 
#define tuklib_memcpy_aligned(dest, src, size)    memcpy(dest, src, size)
 
#define TUKLIB_USE_UNSAFE_ALIGNED_READS   1
 
#define aligned_write16be(buf, num)   aligned_write16ne((buf), conv16be(num))
 
#define aligned_write16le(buf, num)   aligned_write16ne((buf), conv16le(num))
 
#define aligned_write32be(buf, num)   aligned_write32ne((buf), conv32be(num))
 
#define aligned_write32le(buf, num)   aligned_write32ne((buf), conv32le(num))
 
#define aligned_write64be(buf, num)   aligned_write64ne((buf), conv64be(num))
 
#define aligned_write64le(buf, num)   aligned_write64ne((buf), conv64le(num))
 
#define bsf32   ctz32
 

Functions

static uint16_t read16ne (const uint8_t *buf)
 
static uint32_t read32ne (const uint8_t *buf)
 
static uint64_t read64ne (const uint8_t *buf)
 
static void write16ne (uint8_t *buf, uint16_t num)
 
static void write32ne (uint8_t *buf, uint32_t num)
 
static void write64ne (uint8_t *buf, uint64_t num)
 
static uint16_t read16be (const uint8_t *buf)
 
static uint16_t read16le (const uint8_t *buf)
 
static uint32_t read32be (const uint8_t *buf)
 
static uint32_t read32le (const uint8_t *buf)
 
static void write16be (uint8_t *buf, uint16_t num)
 
static void write32be (uint8_t *buf, uint32_t num)
 
static uint16_t aligned_read16ne (const uint8_t *buf)
 
static uint32_t aligned_read32ne (const uint8_t *buf)
 
static uint64_t aligned_read64ne (const uint8_t *buf)
 
static void aligned_write16ne (uint8_t *buf, uint16_t num)
 
static void aligned_write32ne (uint8_t *buf, uint32_t num)
 
static void aligned_write64ne (uint8_t *buf, uint64_t num)
 
static uint16_t aligned_read16be (const uint8_t *buf)
 
static uint16_t aligned_read16le (const uint8_t *buf)
 
static uint32_t aligned_read32be (const uint8_t *buf)
 
static uint32_t aligned_read32le (const uint8_t *buf)
 
static uint64_t aligned_read64be (const uint8_t *buf)
 
static uint64_t aligned_read64le (const uint8_t *buf)
 
static uint32_t bsr32 (uint32_t n)
 
static uint32_t clz32 (uint32_t n)
 
static uint32_t ctz32 (uint32_t n)
 

Detailed Description

Various integer and bit operations.

This file provides macros or functions to do some basic integer and bit operations.

Native endian inline functions (XX = 16, 32, or 64):

  • Unaligned native endian reads: readXXne(ptr)
  • Unaligned native endian writes: writeXXne(ptr, num)
  • Aligned native endian reads: aligned_readXXne(ptr)
  • Aligned native endian writes: aligned_writeXXne(ptr, num)

Endianness-converting integer operations (these can be macros!) (XX = 16, 32, or 64; Y = b or l):

  • Byte swapping: bswapXX(num)
  • Byte order conversions to/from native (byteswaps if Y isn't the native endianness): convXXYe(num)
  • Unaligned reads (16/32-bit only): readXXYe(ptr)
  • Unaligned writes (16/32-bit only): writeXXYe(ptr, num)
  • Aligned reads: aligned_readXXYe(ptr)
  • Aligned writes: aligned_writeXXYe(ptr, num)

Since the above can macros, the arguments should have no side effects because they may be evaluated more than once.

Bit scan operations for non-zero 32-bit integers (inline functions):

  • Bit scan reverse (find highest non-zero bit): bsr32(num)
  • Count leading zeros: clz32(num)
  • Count trailing zeros: ctz32(num)
  • Bit scan forward (simply an alias for ctz32()): bsf32(num)

The above bit scan operations return 0-31. If num is zero, the result is undefined.

Definition in file tuklib_integer.h.

Macro Definition Documentation

◆ aligned_write16be

#define aligned_write16be (   buf,
  num 
)    aligned_write16ne((buf), conv16be(num))

Definition at line 572 of file tuklib_integer.h.

◆ aligned_write16le

#define aligned_write16le (   buf,
  num 
)    aligned_write16ne((buf), conv16le(num))

Definition at line 573 of file tuklib_integer.h.

◆ aligned_write32be

#define aligned_write32be (   buf,
  num 
)    aligned_write32ne((buf), conv32be(num))

Definition at line 574 of file tuklib_integer.h.

◆ aligned_write32le

#define aligned_write32le (   buf,
  num 
)    aligned_write32ne((buf), conv32le(num))

Definition at line 575 of file tuklib_integer.h.

◆ aligned_write64be

#define aligned_write64be (   buf,
  num 
)    aligned_write64ne((buf), conv64be(num))

Definition at line 576 of file tuklib_integer.h.

◆ aligned_write64le

#define aligned_write64le (   buf,
  num 
)    aligned_write64ne((buf), conv64le(num))

Definition at line 577 of file tuklib_integer.h.

◆ bsf32

#define bsf32   ctz32

Definition at line 740 of file tuklib_integer.h.

◆ bswap16

#define bswap16 (   n)
Value:
(uint16_t)( \
(((n) & 0x00FFU) << 8) \
| (((n) & 0xFF00U) >> 8) \
)
int n
Definition: mipsasm.c:19
unsigned short uint16_t
Definition: sftypes.h:30

Definition at line 118 of file tuklib_integer.h.

◆ bswap32

#define bswap32 (   n)
Value:
(uint32_t)( \
(((n) & UINT32_C(0x000000FF)) << 24) \
| (((n) & UINT32_C(0x0000FF00)) << 8) \
| (((n) & UINT32_C(0x00FF0000)) >> 8) \
| (((n) & UINT32_C(0xFF000000)) >> 24) \
)
unsigned int uint32_t
Definition: sftypes.h:29
#define UINT32_C(val)

Definition at line 125 of file tuklib_integer.h.

◆ bswap64

#define bswap64 (   n)
Value:
(uint64_t)( \
(((n) & UINT64_C(0x00000000000000FF)) << 56) \
| (((n) & UINT64_C(0x000000000000FF00)) << 40) \
| (((n) & UINT64_C(0x0000000000FF0000)) << 24) \
| (((n) & UINT64_C(0x00000000FF000000)) << 8) \
| (((n) & UINT64_C(0x000000FF00000000)) >> 8) \
| (((n) & UINT64_C(0x0000FF0000000000)) >> 24) \
| (((n) & UINT64_C(0x00FF000000000000)) >> 40) \
| (((n) & UINT64_C(0xFF00000000000000)) >> 56) \
)
unsigned long uint64_t
Definition: sftypes.h:28
#define UINT64_C(val)

Definition at line 134 of file tuklib_integer.h.

◆ conv16be

#define conv16be (   num)    bswap16(num)

Definition at line 168 of file tuklib_integer.h.

◆ conv16le

#define conv16le (   num)    ((uint16_t)(num))

Definition at line 177 of file tuklib_integer.h.

◆ conv32be

#define conv32be (   num)    bswap32(num)

Definition at line 171 of file tuklib_integer.h.

◆ conv32le

#define conv32le (   num)    ((uint32_t)(num))

Definition at line 180 of file tuklib_integer.h.

◆ conv64be

#define conv64be (   num)    bswap64(num)

Definition at line 174 of file tuklib_integer.h.

◆ conv64le

#define conv64le (   num)    ((uint64_t)(num))

Definition at line 183 of file tuklib_integer.h.

◆ tuklib_memcpy_aligned

#define tuklib_memcpy_aligned (   dest,
  src,
  size 
)     memcpy(dest, src, size)

Definition at line 437 of file tuklib_integer.h.

◆ TUKLIB_USE_UNSAFE_ALIGNED_READS

#define TUKLIB_USE_UNSAFE_ALIGNED_READS   1

Definition at line 440 of file tuklib_integer.h.

◆ write16le

#define write16le (   buf,
  num 
)    write16ne(buf, conv16le(num))

Definition at line 356 of file tuklib_integer.h.

◆ write32le

#define write32le (   buf,
  num 
)    write32ne(buf, conv32le(num))

Definition at line 357 of file tuklib_integer.h.

Function Documentation

◆ aligned_read16be()

static uint16_t aligned_read16be ( const uint8_t buf)
inlinestatic

Definition at line 524 of file tuklib_integer.h.

525 {
527  return conv16be(num);
528 }
voidpf void * buf
Definition: ioapi.h:138
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
static uint16_t aligned_read16ne(const uint8_t *buf)
#define conv16be(num)

References aligned_read16ne(), conv16be, and num.

◆ aligned_read16le()

static uint16_t aligned_read16le ( const uint8_t buf)
inlinestatic

Definition at line 532 of file tuklib_integer.h.

533 {
535  return conv16le(num);
536 }
#define conv16le(num)

References aligned_read16ne(), conv16le, and num.

◆ aligned_read16ne()

static uint16_t aligned_read16ne ( const uint8_t buf)
inlinestatic

Definition at line 446 of file tuklib_integer.h.

447 {
448 #if defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING) \
449  || defined(TUKLIB_USE_UNSAFE_ALIGNED_READS)
450  return *(const uint16_t *)buf;
451 #else
452  uint16_t num;
453  tuklib_memcpy_aligned(&num, buf, sizeof(num));
454  return num;
455 #endif
456 }
#define tuklib_memcpy_aligned(dest, src, size)

References num, and tuklib_memcpy_aligned.

Referenced by aligned_read16be(), and aligned_read16le().

◆ aligned_read32be()

static uint32_t aligned_read32be ( const uint8_t buf)
inlinestatic

Definition at line 540 of file tuklib_integer.h.

541 {
543  return conv32be(num);
544 }
#define conv32be(num)
static uint32_t aligned_read32ne(const uint8_t *buf)

References aligned_read32ne(), conv32be, and num.

◆ aligned_read32le()

static uint32_t aligned_read32le ( const uint8_t buf)
inlinestatic

Definition at line 548 of file tuklib_integer.h.

549 {
551  return conv32le(num);
552 }
#define conv32le(num)

References aligned_read32ne(), conv32le, and num.

◆ aligned_read32ne()

static uint32_t aligned_read32ne ( const uint8_t buf)
inlinestatic

Definition at line 460 of file tuklib_integer.h.

461 {
462 #if defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING) \
463  || defined(TUKLIB_USE_UNSAFE_ALIGNED_READS)
464  return *(const uint32_t *)buf;
465 #else
466  uint32_t num;
467  tuklib_memcpy_aligned(&num, buf, sizeof(num));
468  return num;
469 #endif
470 }

References num, and tuklib_memcpy_aligned.

Referenced by aligned_read32be(), aligned_read32le(), and LZMA_API().

◆ aligned_read64be()

static uint64_t aligned_read64be ( const uint8_t buf)
inlinestatic

Definition at line 556 of file tuklib_integer.h.

557 {
559  return conv64be(num);
560 }
#define conv64be(num)
static uint64_t aligned_read64ne(const uint8_t *buf)

References aligned_read64ne(), conv64be, and num.

◆ aligned_read64le()

static uint64_t aligned_read64le ( const uint8_t buf)
inlinestatic

Definition at line 564 of file tuklib_integer.h.

565 {
567  return conv64le(num);
568 }
#define conv64le(num)

References aligned_read64ne(), conv64le, and num.

◆ aligned_read64ne()

static uint64_t aligned_read64ne ( const uint8_t buf)
inlinestatic

Definition at line 474 of file tuklib_integer.h.

475 {
476 #if defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING) \
477  || defined(TUKLIB_USE_UNSAFE_ALIGNED_READS)
478  return *(const uint64_t *)buf;
479 #else
480  uint64_t num;
481  tuklib_memcpy_aligned(&num, buf, sizeof(num));
482  return num;
483 #endif
484 }

References num, and tuklib_memcpy_aligned.

Referenced by aligned_read64be(), and aligned_read64le().

◆ aligned_write16ne()

static void aligned_write16ne ( uint8_t buf,
uint16_t  num 
)
inlinestatic

Definition at line 488 of file tuklib_integer.h.

489 {
490 #ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
491  *(uint16_t *)buf = num;
492 #else
493  tuklib_memcpy_aligned(buf, &num, sizeof(num));
494 #endif
495  return;
496 }

References num, and tuklib_memcpy_aligned.

◆ aligned_write32ne()

static void aligned_write32ne ( uint8_t buf,
uint32_t  num 
)
inlinestatic

Definition at line 500 of file tuklib_integer.h.

501 {
502 #ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
503  *(uint32_t *)buf = num;
504 #else
505  tuklib_memcpy_aligned(buf, &num, sizeof(num));
506 #endif
507  return;
508 }

References num, and tuklib_memcpy_aligned.

◆ aligned_write64ne()

static void aligned_write64ne ( uint8_t buf,
uint64_t  num 
)
inlinestatic

Definition at line 512 of file tuklib_integer.h.

513 {
514 #ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
515  *(uint64_t *)buf = num;
516 #else
517  tuklib_memcpy_aligned(buf, &num, sizeof(num));
518 #endif
519  return;
520 }

References num, and tuklib_memcpy_aligned.

◆ bsr32()

static uint32_t bsr32 ( uint32_t  n)
inlinestatic

Definition at line 585 of file tuklib_integer.h.

586 {
587  // Check for ICC first, since it tends to define __GNUC__ too.
588 #if defined(__INTEL_COMPILER)
589  return _bit_scan_reverse(n);
590 
591 #elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
592  // GCC >= 3.4 has __builtin_clz(), which gives good results on
593  // multiple architectures. On x86, __builtin_clz() ^ 31U becomes
594  // either plain BSR (so the XOR gets optimized away) or LZCNT and
595  // XOR (if -march indicates that SSE4a instructions are supported).
596  return (uint32_t)__builtin_clz(n) ^ 31U;
597 
598 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
599  uint32_t i;
600  __asm__("bsrl %1, %0" : "=r" (i) : "rm" (n));
601  return i;
602 
603 #elif defined(_MSC_VER)
604  unsigned long i;
605  _BitScanReverse(&i, n);
606  return i;
607 
608 #else
609  uint32_t i = 31;
610 
611  if ((n & 0xFFFF0000) == 0) {
612  n <<= 16;
613  i = 15;
614  }
615 
616  if ((n & 0xFF000000) == 0) {
617  n <<= 8;
618  i -= 8;
619  }
620 
621  if ((n & 0xF0000000) == 0) {
622  n <<= 4;
623  i -= 4;
624  }
625 
626  if ((n & 0xC0000000) == 0) {
627  n <<= 2;
628  i -= 2;
629  }
630 
631  if ((n & 0x80000000) == 0)
632  --i;
633 
634  return i;
635 #endif
636 }
lzma_index ** i
Definition: index.h:629

References i, and n.

Referenced by index_tree_append().

◆ clz32()

static uint32_t clz32 ( uint32_t  n)
inlinestatic

Definition at line 640 of file tuklib_integer.h.

641 {
642 #if defined(__INTEL_COMPILER)
643  return _bit_scan_reverse(n) ^ 31U;
644 
645 #elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
646  return (uint32_t)__builtin_clz(n);
647 
648 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
649  uint32_t i;
650  __asm__("bsrl %1, %0\n\t"
651  "xorl $31, %0"
652  : "=r" (i) : "rm" (n));
653  return i;
654 
655 #elif defined(_MSC_VER)
656  unsigned long i;
657  _BitScanReverse(&i, n);
658  return i ^ 31U;
659 
660 #else
661  uint32_t i = 0;
662 
663  if ((n & 0xFFFF0000) == 0) {
664  n <<= 16;
665  i = 16;
666  }
667 
668  if ((n & 0xFF000000) == 0) {
669  n <<= 8;
670  i += 8;
671  }
672 
673  if ((n & 0xF0000000) == 0) {
674  n <<= 4;
675  i += 4;
676  }
677 
678  if ((n & 0xC0000000) == 0) {
679  n <<= 2;
680  i += 2;
681  }
682 
683  if ((n & 0x80000000) == 0)
684  ++i;
685 
686  return i;
687 #endif
688 }

References i, and n.

◆ ctz32()

static uint32_t ctz32 ( uint32_t  n)
inlinestatic

Definition at line 692 of file tuklib_integer.h.

693 {
694 #if defined(__INTEL_COMPILER)
695  return _bit_scan_forward(n);
696 
697 #elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX >= UINT32_MAX
698  return (uint32_t)__builtin_ctz(n);
699 
700 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
701  uint32_t i;
702  __asm__("bsfl %1, %0" : "=r" (i) : "rm" (n));
703  return i;
704 
705 #elif defined(_MSC_VER)
706  unsigned long i;
707  _BitScanForward(&i, n);
708  return i;
709 
710 #else
711  uint32_t i = 0;
712 
713  if ((n & 0x0000FFFF) == 0) {
714  n >>= 16;
715  i = 16;
716  }
717 
718  if ((n & 0x000000FF) == 0) {
719  n >>= 8;
720  i += 8;
721  }
722 
723  if ((n & 0x0000000F) == 0) {
724  n >>= 4;
725  i += 4;
726  }
727 
728  if ((n & 0x00000003) == 0) {
729  n >>= 2;
730  i += 2;
731  }
732 
733  if ((n & 0x00000001) == 0)
734  ++i;
735 
736  return i;
737 #endif
738 }

References i, and n.

Referenced by index_tree_append().

◆ read16be()

static uint16_t read16be ( const uint8_t buf)
inlinestatic

Definition at line 289 of file tuklib_integer.h.

290 {
291 #if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
293  return conv16be(num);
294 #else
295  uint16_t num = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
296  return num;
297 #endif
298 }
static uint16_t read16ne(const uint8_t *buf)

References conv16be, num, and read16ne().

◆ read16le()

static uint16_t read16le ( const uint8_t buf)
inlinestatic

Definition at line 302 of file tuklib_integer.h.

303 {
304 #if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
306  return conv16le(num);
307 #else
308  uint16_t num = ((uint16_t)buf[0]) | ((uint16_t)buf[1] << 8);
309  return num;
310 #endif
311 }

References conv16le, num, and read16ne().

◆ read16ne()

static uint16_t read16ne ( const uint8_t buf)
inlinestatic

Definition at line 208 of file tuklib_integer.h.

209 {
210 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
211  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
212  return *(const uint16_t *)buf;
213 #else
214  uint16_t num;
215  memcpy(&num, buf, sizeof(num));
216  return num;
217 #endif
218 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))

References memcpy(), and num.

Referenced by read16be(), and read16le().

◆ read32be()

static uint32_t read32be ( const uint8_t buf)
inlinestatic

Definition at line 315 of file tuklib_integer.h.

316 {
317 #if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
319  return conv32be(num);
320 #else
321  uint32_t num = (uint32_t)buf[0] << 24;
322  num |= (uint32_t)buf[1] << 16;
323  num |= (uint32_t)buf[2] << 8;
324  num |= (uint32_t)buf[3];
325  return num;
326 #endif
327 }
static uint32_t read32ne(const uint8_t *buf)

References conv32be, num, and read32ne().

◆ read32le()

static uint32_t read32le ( const uint8_t buf)
inlinestatic

Definition at line 331 of file tuklib_integer.h.

332 {
333 #if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
335  return conv32le(num);
336 #else
337  uint32_t num = (uint32_t)buf[0];
338  num |= (uint32_t)buf[1] << 8;
339  num |= (uint32_t)buf[2] << 16;
340  num |= (uint32_t)buf[3] << 24;
341  return num;
342 #endif
343 }

References conv32le, num, and read32ne().

Referenced by LZMA_API(), lzma_lzma_props_decode(), and lzma_simple_props_decode().

◆ read32ne()

static uint32_t read32ne ( const uint8_t buf)
inlinestatic

Definition at line 222 of file tuklib_integer.h.

223 {
224 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
225  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
226  return *(const uint32_t *)buf;
227 #else
228  uint32_t num;
229  memcpy(&num, buf, sizeof(num));
230  return num;
231 #endif
232 }

References memcpy(), and num.

Referenced by read32be(), and read32le().

◆ read64ne()

static uint64_t read64ne ( const uint8_t buf)
inlinestatic

Definition at line 236 of file tuklib_integer.h.

237 {
238 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
239  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
240  return *(const uint64_t *)buf;
241 #else
242  uint64_t num;
243  memcpy(&num, buf, sizeof(num));
244  return num;
245 #endif
246 }

References memcpy(), and num.

◆ write16be()

static void write16be ( uint8_t buf,
uint16_t  num 
)
inlinestatic

Definition at line 363 of file tuklib_integer.h.

364 {
365  buf[0] = (uint8_t)(num >> 8);
366  buf[1] = (uint8_t)num;
367  return;
368 }
unsigned char uint8_t
Definition: sftypes.h:31

References num.

◆ write16ne()

static void write16ne ( uint8_t buf,
uint16_t  num 
)
inlinestatic

Definition at line 250 of file tuklib_integer.h.

251 {
252 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
253  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
254  *(uint16_t *)buf = num;
255 #else
256  memcpy(buf, &num, sizeof(num));
257 #endif
258  return;
259 }

References memcpy(), and num.

◆ write32be()

static void write32be ( uint8_t buf,
uint32_t  num 
)
inlinestatic

Definition at line 385 of file tuklib_integer.h.

386 {
387  buf[0] = (uint8_t)(num >> 24);
388  buf[1] = (uint8_t)(num >> 16);
389  buf[2] = (uint8_t)(num >> 8);
390  buf[3] = (uint8_t)num;
391  return;
392 }

References num.

◆ write32ne()

static void write32ne ( uint8_t buf,
uint32_t  num 
)
inlinestatic

Definition at line 263 of file tuklib_integer.h.

264 {
265 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
266  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
267  *(uint32_t *)buf = num;
268 #else
269  memcpy(buf, &num, sizeof(num));
270 #endif
271  return;
272 }

References memcpy(), and num.

◆ write64ne()

static void write64ne ( uint8_t buf,
uint64_t  num 
)
inlinestatic

Definition at line 276 of file tuklib_integer.h.

277 {
278 #if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
279  && defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
280  *(uint64_t *)buf = num;
281 #else
282  memcpy(buf, &num, sizeof(num));
283 #endif
284  return;
285 }

References memcpy(), and num.