minecraft-pi-reborn/libreborn/include/libreborn/util.h

51 lines
1.1 KiB
C
Raw Normal View History

2021-06-17 21:32:24 +00:00
#pragma once
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>
#include "log.h"
// Check Memory Allocation
#define ALLOC_CHECK(obj) \
{ \
if (obj == NULL) { \
2022-04-15 01:12:42 +00:00
ERR("Memory Allocation Failed"); \
2021-06-17 21:32:24 +00:00
} \
}
// Hook Library Function
#define HOOK(name, return_type, args) \
typedef return_type (*name##_t)args; \
static name##_t real_##name = NULL; \
\
__attribute__((__unused__)) static void ensure_##name() { \
if (!real_##name) { \
dlerror(); \
real_##name = (name##_t) dlsym(RTLD_NEXT, #name); \
if (!real_##name) { \
ERR("Error Resolving Symbol: " #name ": %s", dlerror()); \
2021-06-17 21:32:24 +00:00
} \
} \
2021-07-05 01:23:12 +00:00
} \
2021-06-17 21:32:24 +00:00
\
__attribute__((__used__)) return_type name args
2022-03-14 23:09:25 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2021-06-17 21:32:24 +00:00
// Safe Version Of pipe()
2022-03-14 23:09:25 +00:00
void safe_pipe2(int pipefd[2], int flags);
// Check If Two Percentages Are Different Enough To Be Logged
int is_progress_difference_significant(int32_t new_val, int32_t old_val);
2022-03-14 23:09:25 +00:00
2022-09-25 23:35:51 +00:00
// Lock File
int lock_file(const char *file);
void unlock_file(const char *file, int fd);
2022-03-14 23:09:25 +00:00
#ifdef __cplusplus
2021-06-17 21:32:24 +00:00
}
2022-03-14 23:09:25 +00:00
#endif