X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=odr%2Fodr_mem.c;h=f938a687fc590d9026fbc1b6b194416ad91a0f1a;hp=f87e5ca7eb1d1cb554a39a2c4b126662b9f942df;hb=8d08fd5b79e49e14ca014de8e6bed12a2cc0468d;hpb=044d170f0a963555486df54653cd2fdc5815928b diff --git a/odr/odr_mem.c b/odr/odr_mem.c index f87e5ca..f938a68 100644 --- a/odr/odr_mem.c +++ b/odr/odr_mem.c @@ -1,10 +1,29 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-2001, Index Data * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_mem.c,v $ - * Revision 1.13 1998-02-11 11:53:34 adam + * Revision 1.19 2001-03-25 21:55:12 adam + * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate. + * + * Revision 1.18 2000/02/29 13:44:55 adam + * Check for config.h (currently not generated). + * + * Revision 1.17 2000/01/31 13:15:21 adam + * Removed uses of assert(3). Cleanup of ODR. CCL parser update so + * that some characters are not surrounded by spaces in resulting term. + * ILL-code updates. + * + * Revision 1.16 1999/11/30 13:47:11 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.15 1999/03/31 11:18:25 adam + * Implemented odr_strdup. Added Reference ID to backend server API. + * + * Revision 1.14 1998/07/20 12:38:15 adam + * More LOG_DEBUG-diagnostics. + * + * Revision 1.13 1998/02/11 11:53:34 adam * Changed code so that it compiles as C++. * * Revision 1.12 1995/11/08 17:41:33 quinn @@ -46,10 +65,13 @@ * Beginning to add memory management to odr * */ +#if HAVE_CONFIG_H +#include +#endif #include -#include -#include +#include +#include /* ------------------------ NIBBLE MEMORY ---------------------- */ @@ -71,6 +93,16 @@ void *odr_malloc(ODR o, int size) return nmem_malloc(o ? o->mem : 0, size); } +char *odr_strdup(ODR o, const char *str) +{ + return nmem_strdup(o->mem, str); +} + +int *odr_intdup(ODR o, int v) +{ + return nmem_intdup(o->mem, v); +} + int odr_total(ODR o) { return o->mem ? nmem_total(o->mem) : 0; @@ -79,7 +111,7 @@ int odr_total(ODR o) /* ---------- memory management for data encoding ----------*/ -int odr_grow_block(odr_ecblock *b, int min_bytes) +int odr_grow_block(ODR b, int min_bytes) { int togrow; @@ -91,9 +123,11 @@ int odr_grow_block(odr_ecblock *b, int min_bytes) togrow = b->size; if (togrow < min_bytes) togrow = min_bytes; - if (b->size && !(b->buf =(unsigned char *)xrealloc(b->buf, b->size += togrow))) + if (b->size && !(b->buf = + (unsigned char *) xrealloc(b->buf, b->size += togrow))) abort(); - else if (!b->size && !(b->buf = (unsigned char *)xmalloc(b->size = togrow))) + else if (!b->size && !(b->buf = (unsigned char *) + xmalloc(b->size = togrow))) abort(); #ifdef ODR_DEBUG fprintf(stderr, "New size for encode_buffer: %d\n", b->size); @@ -103,29 +137,29 @@ int odr_grow_block(odr_ecblock *b, int min_bytes) int odr_write(ODR o, unsigned char *buf, int bytes) { - if (o->ecb.pos + bytes >= o->ecb.size && odr_grow_block(&o->ecb, bytes)) + if (o->pos + bytes >= o->size && odr_grow_block(o, bytes)) { o->error = OSPACE; return -1; } - memcpy(o->ecb.buf + o->ecb.pos, buf, bytes); - o->ecb.pos += bytes; - if (o->ecb.pos > o->ecb.top) - o->ecb.top = o->ecb.pos; + memcpy(o->buf + o->pos, buf, bytes); + o->pos += bytes; + if (o->pos > o->top) + o->top = o->pos; return 0; } int odr_seek(ODR o, int whence, int offset) { if (whence == ODR_S_CUR) - offset += o->ecb.pos; + offset += o->pos; else if (whence == ODR_S_END) - offset += o->ecb.top; - if (offset > o->ecb.size && odr_grow_block(&o->ecb, offset - o->ecb.size)) + offset += o->top; + if (offset > o->size && odr_grow_block(o, offset - o->size)) { o->error = OSPACE; return -1; } - o->ecb.pos = offset; + o->pos = offset; return 0; }