Files

41 lines
1.1 KiB
C

#ifndef VANILLA_UTIL_H
#define VANILLA_UTIL_H
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define CLAMP(x, min, max) (MIN(MAX(x, min), max))
#if defined(_WIN32)
// Windows has no htobe32, and is always virtually little-endiam
#define htobe32(x) htonl(x)
#define le16toh(x) (x)
#elif defined(__APPLE__)
// macOS has no htobe32
#include <libkern/OSByteOrder.h>
#define htobe32(x) OSSwapHostToBigInt32(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#endif // __APPLE__
size_t read_line_from_fd(int fd, char *output, size_t max_output_size);
size_t read_line_from_file(FILE *file, char *output, size_t max_output_size);
size_t get_max_path_length();
void clear_interrupt();
int is_interrupted();
void force_interrupt();
void install_interrupt_handler();
void uninstall_interrupt_handler();
size_t get_millis();
unsigned int reverse_bits(unsigned int b, int bit_count);
uint16_t crc16(const void* data, size_t len);
void print_hex(const void *data, size_t len);
#endif // VANILLA_UTIL_H