From c1fe19d4c1db610692365472a90f4661e48449c1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 9 Oct 2000 20:06:30 +0000 Subject: Bug ugly formatting update --- libc/stdlib/malloc/Makefile | 17 ++++++++++++---- libc/stdlib/malloc/alloc.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 libc/stdlib/malloc/alloc.c (limited to 'libc/stdlib/malloc') diff --git a/libc/stdlib/malloc/Makefile b/libc/stdlib/malloc/Makefile index ba2567f12..fe3f8b424 100644 --- a/libc/stdlib/malloc/Makefile +++ b/libc/stdlib/malloc/Makefile @@ -27,13 +27,22 @@ LIBC=$(TOPDIR)libc.a CSRC=malloc.c COBJS=$(patsubst %.c,%.o, $(CSRC)) +MSRC=alloc.c +MOBJ=malloc_dbg.o free_dbg.o calloc_dbg.o +OBJS=$(COBJS) $(MOBJ) -all: $(COBJS) $(LIBC) +all: $(OBJS) $(LIBC) -$(LIBC): $(COBJS) - $(AR) $(ARFLAGS) $(LIBC) $(COBJS) +$(LIBC): ar-target -$(COBJS): Makefile +ar-target: $(OBJS) + $(AR) $(ARFLAGS) $(LIBC) $(OBJS) + +$(MOBJ): $(MSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + +$(OBJ): Makefile clean: rm -f *.[oa] *~ core + diff --git a/libc/stdlib/malloc/alloc.c b/libc/stdlib/malloc/alloc.c new file mode 100644 index 000000000..b782f6dcf --- /dev/null +++ b/libc/stdlib/malloc/alloc.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include + + +#ifdef L_calloc_dbg + +void * +calloc_dbg(size_t num, size_t size, char * function, char * file, int line) +{ + void * ptr; + fprintf(stderr, "calloc of %d bytes at %s @%s:%d = ", num*size, function, file, line); + ptr = calloc(num,size); + fprintf(stderr, "%p\n", ptr); + return ptr; +} + +#endif + +#ifdef L_malloc_dbg + +void * +malloc_dbg(size_t len, char * function, char * file, int line) +{ + void * result; + fprintf(stderr, "malloc of %d bytes at %s @%s:%d = ", len, function, file, line); + result = malloc(len); + fprintf(stderr, "%p\n", result); + return result; +} + +#endif + +#ifdef L_free_dbg + +void +free_dbg(void * ptr, char * function, char * file, int line) +{ + fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file, line); + free(ptr); +} + +#endif + + -- cgit v1.2.3