Minor adjustments
[yaz-moved-to-github.git] / odr / odr_mem.c
index 4437058..3894907 100644 (file)
@@ -4,7 +4,19 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_mem.c,v $
- * Revision 1.7  1995-09-27 15:02:59  quinn
+ * Revision 1.11  1995-11-01 13:54:43  quinn
+ * Minor adjustments
+ *
+ * Revision 1.10  1995/10/25  16:58:19  quinn
+ * Stupid bug in odr_malloc
+ *
+ * Revision 1.9  1995/10/13  16:08:08  quinn
+ * Added OID utility
+ *
+ * Revision 1.8  1995/09/29  17:12:24  quinn
+ * Smallish
+ *
+ * Revision 1.7  1995/09/27  15:02:59  quinn
  * Modified function heads & prototypes.
  *
  * Revision 1.6  1995/08/21  09:10:41  quinn
@@ -31,7 +43,7 @@
 
 #include <stdlib.h>
 #include <odr.h>
-#include <dmalloc.h>
+#include <xmalloc.h>
 
 /* ------------------------ NIBBLE MEMORY ---------------------- */
 
@@ -75,9 +87,9 @@ static odr_memblock *get_block(int size)
 
        if (get < size)
            get = size;
-       if (!(r = malloc(sizeof(*r))))
+       if (!(r = xmalloc(sizeof(*r))))
            abort();
-       if (!(r->buf = malloc(r->size = get)))
+       if (!(r->buf = xmalloc(r->size = get)))
            abort();
     }
     r->top = 0;
@@ -88,7 +100,7 @@ static odr_memblock *get_block(int size)
 /*
  * Return p to the global freelist.
  */
-void MDF odr_release_mem(ODR_MEM p)
+void odr_release_mem(ODR_MEM p)
 {
     odr_memblock *t;
 
@@ -103,7 +115,7 @@ void MDF odr_release_mem(ODR_MEM p)
 /*
  * Extract the memory control block from o.
  */
-ODR_MEM MDF odr_extract_mem(ODR o)
+ODR_MEM odr_extract_mem(ODR o)
 {
     ODR_MEM r = o->mem;
 
@@ -111,11 +123,18 @@ ODR_MEM MDF odr_extract_mem(ODR o)
     return r;
 }
 
-void MDF *odr_malloc(ODR o, int size)
+void *odr_malloc(ODR o, int size)
 {
-    struct odr_memblock *p = o->mem;
+    struct odr_memblock *p;
     char *r;
 
+    if (!o)
+    {
+       if (!(r = xmalloc(size)))
+           abort();
+       return r;
+    }
+    p = o->mem;
     if (!p || p->size - p->top < size)
        if (!(p = get_block(size)))
            abort();
@@ -133,7 +152,7 @@ void MDF *odr_malloc(ODR o, int size)
     return r;
 }
 
-int MDF odr_total(ODR o)
+int odr_total(ODR o)
 {
     return o->mem ? o->mem->total : 0;
 }
@@ -141,7 +160,7 @@ int MDF odr_total(ODR o)
 /* ---------- memory management for data encoding ----------*/
 
 
-int MDF odr_grow_block(odr_ecblock *b, int min_bytes)
+int odr_grow_block(odr_ecblock *b, int min_bytes)
 {
     int togrow;
 
@@ -153,9 +172,9 @@ int MDF odr_grow_block(odr_ecblock *b, int min_bytes)
        togrow = b->size;
     if (togrow < min_bytes)
        togrow = min_bytes;
-    if (b->size && !(b->buf = realloc(b->buf, b->size += togrow)))
+    if (b->size && !(b->buf =xrealloc(b->buf, b->size += togrow)))
        abort();
-    else if (!b->size && !(b->buf = malloc(b->size = togrow)))
+    else if (!b->size && !(b->buf = xmalloc(b->size = togrow)))
        abort();
 #ifdef ODR_DEBUG
     fprintf(stderr, "New size for encode_buffer: %d\n", b->size);
@@ -163,7 +182,7 @@ int MDF odr_grow_block(odr_ecblock *b, int min_bytes)
     return 0;
 }
 
-int MDF odr_write(ODR o, unsigned char *buf, int 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))
     {
@@ -177,7 +196,7 @@ int MDF odr_write(ODR o, unsigned char *buf, int bytes)
     return 0;
 }
 
-int MDF odr_seek(ODR o, int whence, int offset)
+int odr_seek(ODR o, int whence, int offset)
 {
     if (whence == ODR_S_CUR)
        offset += o->ecb.pos;