Reformat
[yaz-moved-to-github.git] / src / nmem.c
index 93988b5..508cc6a 100644 (file)
@@ -8,10 +8,8 @@
  * \brief Implements Nibble Memory
  *
  * This is a simple and fairly wasteful little module for nibble memory
- * allocation. Evemtually we'll put in something better.
+ * allocation.
  *
- * FIXME - it also has some semaphore stuff, and stuff to handle errno.
- *         These should be moved to some other place!
  */
 #if HAVE_CONFIG_H
 #include <config.h>
@@ -38,7 +36,7 @@ struct nmem_block
 
 struct nmem_control
 {
-    int total;
+    size_t total;
     struct nmem_block *blocks;
     struct nmem_control *next;
 };
@@ -68,7 +66,7 @@ static void free_block(struct nmem_block *p)
     xfree(p->buf);
     xfree(p);
     if (log_level)
-        yaz_log (log_level, "nmem free_block p=%p", p);
+        yaz_log(log_level, "nmem free_block p=%p", p);
 }
 
 /*
@@ -80,14 +78,13 @@ static struct nmem_block *get_block(size_t size)
     size_t get = NMEM_CHUNK;
 
     if (log_level)
-        yaz_log (log_level, "nmem get_block size=%ld", (long) size);
+        yaz_log(log_level, "nmem get_block size=%ld", (long) size);
 
-    
     if (get < size)
         get = size;
-    if(log_level)
-        yaz_log (log_level, "nmem get_block alloc new block size=%ld",
-                 (long) get);
+    if (log_level)
+        yaz_log(log_level, "nmem get_block alloc new block size=%ld",
+                (long) get);
     
     r = (struct nmem_block *) xmalloc(sizeof(*r));
     r->buf = (char *)xmalloc(r->size = get);
@@ -99,7 +96,7 @@ void nmem_reset(NMEM n)
 {
     struct nmem_block *t;
     
-    yaz_log (log_level, "nmem_reset p=%p", n);
+    yaz_log(log_level, "nmem_reset p=%p", n);
     if (!n)
         return;
     while (n->blocks)
@@ -111,15 +108,15 @@ void nmem_reset(NMEM n)
     n->total = 0;
 }
 
-void *nmem_malloc(NMEM n, int size)
+void *nmem_malloc(NMEM n, size_t size)
 {
     struct nmem_block *p;
     char *r;
 
     if (!n)
     {
-        yaz_log (YLOG_FATAL, "calling nmem_malloc with an null pointer");
-        abort ();
+        yaz_log(YLOG_FATAL, "calling nmem_malloc with an null pointer");
+        abort();
     }
     p = n->blocks;
     if (!p || p->size < size + p->top)
@@ -135,7 +132,7 @@ void *nmem_malloc(NMEM n, int size)
     return r;
 }
 
-int nmem_total(NMEM n)
+size_t nmem_total(NMEM n)
 {
     return n->total;
 }
@@ -167,7 +164,7 @@ void nmem_destroy(NMEM n)
     xfree(n);
 }
 
-void nmem_transfer (NMEM dst, NMEM src)
+void nmem_transfer(NMEM dst, NMEM src)
 {
     struct nmem_block *t;
     while ((t = src->blocks))