Skip to content

File lt_utils.h

File List > api > lt_utils.h

Go to the documentation of this file.

/* Copyright (c) Kuba Szczodrzyński 2023-02-27. */

#pragma once

#include <libretiny.h>

// https://stackoverflow.com/a/3437484
#define MAX(a, b)                                                                                                      \
    ({                                                                                                                 \
        __typeof__(a) _a = (a);                                                                                        \
        __typeof__(b) _b = (b);                                                                                        \
        _a > _b ? _a : _b;                                                                                             \
    })
#define MIN(a, b)                                                                                                      \
    ({                                                                                                                 \
        __typeof__(a) _a = (a);                                                                                        \
        __typeof__(b) _b = (b);                                                                                        \
        _a < _b ? _a : _b;                                                                                             \
    })

void lt_rand_bytes(uint8_t *buf, size_t len);

void hexdump(
    const uint8_t *buf,
    size_t len,
#ifdef __cplusplus
    uint32_t offset = 0,
    uint8_t width   = 16
#else
    uint32_t offset,
    uint8_t width
#endif
);

char *lt_btox(const uint8_t *src, int len, char *dest);

uint8_t *lt_xtob(const char *src, int len, uint8_t *dest);