| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#if !defined(LIBC_WRAPPERS_H_) |
| 17 |
#define LIBC_WRAPPERS_H_ |
| 18 |
|
| 19 |
#include <assert.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <sys/mman.h> |
| 23 |
#include <sys/types.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#ifndef FORCE_NO_LIBC |
| 27 |
#define GOTCHA_USE_LIBC |
| 28 |
#endif |
| 29 |
|
| 30 |
#if defined(GOTCHA_USE_LIBC) && !defined(BUILDING_LIBC_WRAPPERS) |
| 31 |
|
| 32 |
#define gotcha_malloc malloc |
| 33 |
#define gotcha_realloc realloc |
| 34 |
#define gotcha_free free |
| 35 |
#define gotcha_memcpy memcpy |
| 36 |
#define gotcha_strncmp strncmp |
| 37 |
#define gotcha_strstr strstr |
| 38 |
#define gotcha_assert assert |
| 39 |
#define gotcha_strcmp strcmp |
| 40 |
#define gotcha_getenv getenv |
| 41 |
#define gotcha_getpid getpid |
| 42 |
#define gotcha_getpagesize getpagesize |
| 43 |
#define gotcha_open open |
| 44 |
#define gotcha_mmap mmap |
| 45 |
#define gotcha_atoi atoi |
| 46 |
#define gotcha_close close |
| 47 |
#define gotcha_mprotect mprotect |
| 48 |
#define gotcha_read read |
| 49 |
#define gotcha_memset memset |
| 50 |
#define gotcha_write write |
| 51 |
#define gotcha_strlen strlen |
| 52 |
#define gotcha_strnlen strnlen |
| 53 |
#define gotcha_strtok strtok |
| 54 |
#define gotcha_strncat strncat |
| 55 |
#define gotcha_dbg_printf(A, ...) fprintf(stderr, A, ##__VA_ARGS__) |
| 56 |
pid_t gotcha_gettid(); |
| 57 |
|
| 58 |
#else |
| 59 |
|
| 60 |
void *gotcha_malloc(size_t size); |
| 61 |
void *gotcha_realloc(void *buffer, size_t size); |
| 62 |
void gotcha_free(void *free_me); |
| 63 |
void gotcha_memcpy(void *dest, void *src, size_t size); |
| 64 |
int gotcha_strncmp(const char *in_one, const char *in_two, int max_length); |
| 65 |
char *gotcha_strstr(const char *searchIn, const char *searchFor); |
| 66 |
int gotcha_strcmp(const char *in_one, const char *in_two); |
| 67 |
char *gotcha_getenv(const char *env); |
| 68 |
pid_t gotcha_getpid(); |
| 69 |
pid_t gotcha_gettid(); |
| 70 |
unsigned int gotcha_getpagesize(); |
| 71 |
int gotcha_open(const char *pathname, int flags, ...); |
| 72 |
void *gotcha_mmap(void *addr, size_t length, int prot, int flags, int fd, |
| 73 |
off_t offset); |
| 74 |
int gotcha_atoi(const char *nptr); |
| 75 |
int gotcha_close(int fd); |
| 76 |
int gotcha_mprotect(void *addr, size_t len, int prot); |
| 77 |
ssize_t gotcha_read(int fd, void *buf, size_t count); |
| 78 |
ssize_t gotcha_write(int fd, const void *buf, size_t count); |
| 79 |
void gotcha_assert_fail(const char *s, const char *file, unsigned int line, |
| 80 |
const char *function); |
| 81 |
void *gotcha_memset(void *s, int c, size_t n); |
| 82 |
size_t gotcha_strlen(const char *str); |
| 83 |
size_t gotcha_strnlen(const char *str, size_t max_length); |
| 84 |
char *gotcha_strncat(char *dest, const char *src, size_t n); |
| 85 |
char *gotcha_strtok(char *dest, const char *src, size_t n); |
| 86 |
|
| 87 |
#define gotcha_dbg_printf(FORMAT, ...) \ |
| 88 |
gotcha_int_printf(2, FORMAT, ##__VA_ARGS__) |
| 89 |
|
| 90 |
#define gotcha_assert(A) \ |
| 91 |
do { \ |
| 92 |
if (!(A)) gotcha_assert_fail("" #A, __FILE__, __LINE__, __func__); \ |
| 93 |
} while (0); |
| 94 |
|
| 95 |
#endif |
| 96 |
|
| 97 |
int gotcha_int_printf(int fd, const char *format, ...); |
| 98 |
|
| 99 |
#endif |