Files
linuxSmartie/include/utils.h
2026-05-11 12:12:43 +00:00

47 lines
1.5 KiB
C

#ifndef LINUXSMARTIE_UTILS_H
#define LINUXSMARTIE_UTILS_H
#include <stdbool.h>
#include <time.h>
#if __STDC_VERSION__ >= 202311L
#define C_STD "C23"
#elif __STDC_VERSION__ >= 201710L
#define C_STD "C17"
#elif __STDC_VERSION__ >= 201112L
#define C_STD "C11"
#elif __STDC_VERSION__ >= 199901L
#define C_STD "C99"
#else
#define C_STD "C89"
#endif
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define P_BYTES(bytes, start) pretty_bytes((bytes), (start), (char[16]){0}, 16)
#define P_NUM(num) pretty_num((num), (char[8]){0}, 8)
void timespec_add_ms(struct timespec *ts, uint16_t ms);
uint64_t timespec_diff_us(const struct timespec *a, const struct timespec *b);
char *pretty_num(double num, char *buf, size_t bufsz);
char *pretty_bytes(uint64_t bytes, int8_t start_suffix, char *buf, size_t bufsz);
int get_hwmon_dir(char *path, size_t bufsz);
size_t read_file(const char *dir, const char *file, char *buffer, size_t n);
void fast_read_num_u64(const char *dir, const char *file, char *buf, uint64_t *result, uint32_t divider);
void fast_read_num_u16(const char *dir, const char *file, char *buf, uint16_t *result, uint32_t divider);
void fast_read_num_u8(const char *dir, const char *file, char *buf, uint8_t *result, uint32_t divider);
void fast_read_num_i16(const char *dir, const char *file, char *buf, int16_t *result, uint32_t divider);
void fast_read_num_f(const char *dir, const char *file, char *buf, float *result, uint32_t divider);
#endif