Files
freywaros/src/lib/util.h
T

25 lines
657 B
C

#pragma once
#include <stdint.h>
#define NUL 0 // TODO Fix VSCode thinking `NULL` conflicts with some other definition.
#define ONES(h, l) ((1ULL << ((h) - (l) + 1)) - 1)
#define BITS_R(s, h, l) (((s) >> (l)) & ONES(h, l))
#define BITS_W(s, h, l, v) ((s) = (__typeof__(s))(((s) & ~(ONES(h, l) << (l))) | (((v) & ONES(h, l)) << (l))))
#define STDIN 0
#define STDOUT 1
#define STDERR 2
typedef uint64_t exit_code_t;
#define EXIT_CODE_OK 0
#define EXIT_CODE_NOT_FOUND ((uint64_t)-2)
#define EXIT_CODE_GENERAL_FAILURE ((uint64_t)-1)
static inline void sleep(uint64_t ms) {
for (volatile uint64_t i = 1000000 * ms; i; i--) // Very approximately
;
}