check
This commit is contained in:
parent
0caac11ca8
commit
0b47c2e54b
4
Makefile
4
Makefile
@ -33,7 +33,7 @@ LDLIBS = -fPIC -shared -ldl
|
|||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJECTS)
|
$(NAME): $(OBJECTS)
|
||||||
$(CC) $(CFLAGS) $(OBJECTS) $(LDLIBS) -o $(NAME)
|
$(CC) $(CFLAGS) $(OBJECTS) -o $(NAME) $(LDLIBS)
|
||||||
|
|
||||||
-include ${DEPENDS}
|
-include ${DEPENDS}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ $(OBJ_PATH):
|
|||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
$(OBJ_PATH)/%.o: %.c | $(OBJ_PATH)
|
$(OBJ_PATH)/%.o: %.c | $(OBJ_PATH)
|
||||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ -fPIC
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJECTS) $(OBJ_PATH)
|
$(RM) $(OBJECTS) $(OBJ_PATH)
|
||||||
|
|||||||
10
inc/funfail.h
Normal file
10
inc/funfail.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef FUNFAIL_H
|
||||||
|
#define FUNFAIL_H
|
||||||
|
|
||||||
|
# define _GNU_SOURCE
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
@ -1,6 +1,4 @@
|
|||||||
#include <dlfcn.h>
|
#include "funfail.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef void *(*f)(size_t __nmemb, size_t __size);
|
typedef void *(*f)(size_t __nmemb, size_t __size);
|
||||||
|
|
||||||
|
|||||||
16
src/malloc.c
16
src/malloc.c
@ -1,21 +1,21 @@
|
|||||||
#include <dlfcn.h>
|
#include "funfail.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
typedef void *(*f)(size_t size);
|
||||||
|
|
||||||
typedef void* (*f)(size_t size);
|
void *malloc(size_t size)
|
||||||
|
{
|
||||||
void* malloc(size_t size) {
|
|
||||||
static f og_malloc = NULL;
|
static f og_malloc = NULL;
|
||||||
static int calls = 0;
|
static int calls = 0;
|
||||||
const int MAX_CALLS = getenv("MAX_MALLOC_CALLS") ? atoi(getenv("MAX_MALLOC_CALLS")) : -1;
|
const int MAX_CALLS = getenv("MAX_MALLOC_CALLS") ? atoi(getenv("MAX_MALLOC_CALLS")) : -1;
|
||||||
|
|
||||||
if (!og_malloc) {
|
if (!og_malloc)
|
||||||
|
{
|
||||||
og_malloc = (f)dlsym(RTLD_NEXT, "malloc");
|
og_malloc = (f)dlsym(RTLD_NEXT, "malloc");
|
||||||
}
|
}
|
||||||
|
|
||||||
calls++;
|
calls++;
|
||||||
if (MAX_CALLS < 0 || calls <= MAX_CALLS) {
|
if (MAX_CALLS < 0 || calls <= MAX_CALLS)
|
||||||
|
{
|
||||||
return og_malloc(size);
|
return og_malloc(size);
|
||||||
}
|
}
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
#include <dlfcn.h>
|
#include "funfail.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef ssize_t (*f)(int fd, void *buf, size_t count);
|
typedef ssize_t (*f)(int fd, void *buf, size_t count);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
#include <dlfcn.h>
|
#include "funfail.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef ssize_t (*f)(int fd, const void *buf, size_t count);
|
typedef ssize_t (*f)(int fd, const void *buf, size_t count);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user