X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=odr%2Fodr_mem.c;h=4437058573f8d88b84b7dd97118d2de524cf396e;hb=aa45b978839c268db6eccafc6a13452d99a7929c;hp=01c96f6384b4c05cfadf95cedd7b25ce8e1a9813;hpb=84fdcc95fbd65091100b861671f410313e78eb0e;p=yaz-moved-to-github.git diff --git a/odr/odr_mem.c b/odr/odr_mem.c index 01c96f6..4437058 100644 --- a/odr/odr_mem.c +++ b/odr/odr_mem.c @@ -1,10 +1,19 @@ /* - * Copyright (C) 1994, Index Data I/S - * All rights reserved. + * Copyright (c) 1995, Index Data + * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_mem.c,v $ - * Revision 1.4 1995-05-15 11:56:09 quinn + * Revision 1.7 1995-09-27 15:02:59 quinn + * Modified function heads & prototypes. + * + * Revision 1.6 1995/08/21 09:10:41 quinn + * Smallish fixes to suppport new formats. + * + * Revision 1.5 1995/05/16 08:50:55 quinn + * License, documentation, and memory fixes + * + * Revision 1.4 1995/05/15 11:56:09 quinn * More work on memory management. * * Revision 1.3 1995/04/18 08:15:21 quinn @@ -33,6 +42,7 @@ typedef struct odr_memblock char *buf; int size; int top; + int total; struct odr_memblock *next; } odr_memblock; @@ -71,13 +81,14 @@ static odr_memblock *get_block(int size) abort(); } r->top = 0; + r->total = 0; return r; } /* * Return p to the global freelist. */ -void odr_release_mem(ODR_MEM p) +void MDF odr_release_mem(ODR_MEM p) { odr_memblock *t; @@ -92,7 +103,7 @@ void odr_release_mem(ODR_MEM p) /* * Extract the memory control block from o. */ -ODR_MEM odr_extract_mem(ODR o) +ODR_MEM MDF odr_extract_mem(ODR o) { ODR_MEM r = o->mem; @@ -100,7 +111,7 @@ ODR_MEM odr_extract_mem(ODR o) return r; } -void *odr_malloc(ODR o, int size) +void MDF *odr_malloc(ODR o, int size) { struct odr_memblock *p = o->mem; char *r; @@ -110,19 +121,27 @@ void *odr_malloc(ODR o, int size) abort(); else { + if (o->mem) + p->total = o->mem->total; p->next = o->mem; o->mem = p; } r = p->buf + p->top; /* align size */ p->top += (size + (sizeof(long) - 1)) & ~(sizeof(long) - 1); + p->total += size; return r; } +int MDF odr_total(ODR o) +{ + return o->mem ? o->mem->total : 0; +} + /* ---------- memory management for data encoding ----------*/ -int odr_grow_block(odr_ecblock *b, int min_bytes) +int MDF odr_grow_block(odr_ecblock *b, int min_bytes) { int togrow; @@ -144,7 +163,7 @@ int odr_grow_block(odr_ecblock *b, int min_bytes) return 0; } -int odr_write(ODR o, unsigned char *buf, int bytes) +int MDF odr_write(ODR o, unsigned char *buf, int bytes) { if (o->ecb.pos + bytes >= o->ecb.size && odr_grow_block(&o->ecb, bytes)) { @@ -158,7 +177,7 @@ int odr_write(ODR o, unsigned char *buf, int bytes) return 0; } -int odr_seek(ODR o, int whence, int offset) +int MDF odr_seek(ODR o, int whence, int offset) { if (whence == ODR_S_CUR) offset += o->ecb.pos;