diff options
| author | isaki <isaki@NetBSD.org> | 2007-11-24 13:20:53 +0000 |
|---|---|---|
| committer | isaki <isaki@NetBSD.org> | 2007-11-24 13:20:53 +0000 |
| commit | 1c038e6834cae6806ebb97ae00a41d67e4d72ae1 (patch) | |
| tree | eab430c54f7ca1bc68225b960a8f82356c93bf2f /sys/lib/libsa/alloc.c | |
| parent | 9ce1f92af748ec8139d3601fdf3b136b600eb57f (diff) | |
style, indent, and ANSI-fy.
Diffstat (limited to 'sys/lib/libsa/alloc.c')
| -rw-r--r-- | sys/lib/libsa/alloc.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/sys/lib/libsa/alloc.c b/sys/lib/libsa/alloc.c index 789a7318eb5..9d880bc1e1d 100644 --- a/sys/lib/libsa/alloc.c +++ b/sys/lib/libsa/alloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: alloc.c,v 1.21 2006/01/25 18:27:23 christos Exp $ */ +/* $NetBSD: alloc.c,v 1.22 2007/11/24 13:20:53 isaki Exp $ */ /* * Copyright (c) 1993 @@ -145,10 +145,11 @@ struct fl { #ifdef HEAP_VARIABLE static char *top, *heapstart, *heaplimit; -void setheap(void *start, void *limit) +void +setheap(void *start, void *limit) { - heapstart = top = start; - heaplimit = limit; + heapstart = top = start; + heaplimit = limit; } #define HEAP_START heapstart #define HEAP_LIMIT heaplimit @@ -157,7 +158,7 @@ void setheap(void *start, void *limit) extern char end[]; #define HEAP_START end #endif -static char *top = (char*)HEAP_START; +static char *top = (char *)HEAP_START; #endif /* HEAP_VARIABLE */ void * @@ -188,11 +189,11 @@ alloc(size_t size) if ((*f)->size < bestsize) { /* keep best fit */ - bestf = f; - bestsize = (*f)->size; - } - } - f = &((*f)->next); + bestf = f; + bestsize = (*f)->size; + } + } + f = &((*f)->next); } /* no match in freelist if bestsize unchanged */ @@ -200,25 +201,25 @@ alloc(size_t size) #endif if (failed) { /* nothing found */ - /* + /* * allocate from heap, keep chunk len in * first word */ - help = top; + help = top; /* make _sure_ the region can hold a struct fl. */ if (size < ALIGN(sizeof (struct fl *))) size = ALIGN(sizeof (struct fl *)); top += ALIGN(sizeof(unsigned)) + ALIGN(size); #ifdef HEAP_LIMIT - if (top > (char*)HEAP_LIMIT) - panic("heap full (0x%lx+%zu)", help, size); + if (top > (char *)HEAP_LIMIT) + panic("heap full (0x%lx+%zu)", help, size); #endif *(unsigned *)(void *)help = (unsigned)ALIGN(size); #ifdef ALLOC_TRACE printf("=%lx\n", (u_long)help + ALIGN(sizeof(unsigned))); #endif - return(help + ALIGN(sizeof(unsigned))); + return help + ALIGN(sizeof(unsigned)); } /* we take the best fit */ @@ -227,14 +228,14 @@ alloc(size_t size) #ifndef ALLOC_FIRST_FIT found: #endif - /* remove from freelist */ - help = (char *)(void *)*f; + /* remove from freelist */ + help = (char *)(void *)*f; *f = (*f)->next; #ifdef ALLOC_TRACE printf("=%lx (origsize %u)\n", (u_long)help + ALIGN(sizeof(unsigned)), *(unsigned *)help); #endif - return(help + ALIGN(sizeof(unsigned))); + return help + ALIGN(sizeof(unsigned)); } void @@ -242,14 +243,15 @@ void dealloc(void *ptr, size_t size) { struct fl *f = - (struct fl *)(void *)((char*)(void *)ptr - ALIGN(sizeof(unsigned))); + (struct fl *)(void *)((char *)(void *)ptr - ALIGN(sizeof(unsigned))); #ifdef ALLOC_TRACE printf("dealloc(%lx, %zu) (origsize %u)\n", (u_long)ptr, size, f->size); #endif #ifdef DEBUG - if (size > (size_t)f->size) - printf("dealloc %u bytes @%lx, should be <=%u\n", - size, (u_long)ptr, f->size); + if (size > (size_t)f->size) { + printf("dealloc %u bytes @%lx, should be <=%u\n", + size, (u_long)ptr, f->size); + } if (ptr < (void *)HEAP_START) printf("dealloc: %lx before start of heap.\n", (u_long)ptr); |
