Create a branch by copying library-split to avoid having to merge from git.
[SXSI/TextCollection.git] / swcsa / utils / basics.c
index 398e975..c9cb275 100755 (executable)
@@ -1,3 +1,6 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 // Basics
 
@@ -7,9 +10,9 @@
 #include <stdlib.h>
 
                // Memory management
-       
-       void *Malloc (int n)
-       
+
+static void *Malloc (size_t n)
+
           { void *p;
             if (n == 0) return NULL;
             p = (void*) malloc (n);
                }
             return p;
           }
-       
-       void Free (void *p)
-       
-          { if (p) free (p); 
+
+static void Free (void *p)
+
+          { if (p) free (p);
           }
-       
-       void *Realloc (void *p, int n)
-       
+
+static void *Realloc (void *p, size_t n)
+
           { if (p == NULL) return Malloc (n);
             if (n == 0) { Free(p); return NULL; }
             p = (void*) realloc (p,n);
@@ -41,7 +44,7 @@
 
         // bits needed to represent a number between 0 and n
 
-uint bits (uint n)
+uint _bits (uint n)
 
    { uint b = 0;
      while (n)
@@ -68,7 +71,7 @@ uint bitread (uint *e, uint p, uint len)
 
        // writes e[p..p+len-1] = s, len <= W
 
-void bitwrite (register uint *e, register uint p, 
+void bitwrite (register uint *e, register uint p,
               register uint len, register uint s)
 
    { e += p/W; p %= W;
@@ -89,7 +92,7 @@ void bitwrite (register uint *e, register uint p,
    }
        // writes e[p..p+len-1] = 0
 
-void bitzero2 (register uint *e, register uint p, 
+void bitzero2 (register uint *e, register uint p,
               register uint len)
 
    { e += p/W; p %= W;
@@ -105,3 +108,6 @@ void bitzero2 (register uint *e, register uint p,
      if (len > 0)
        *e &= ~(((1<<len)-1)<<p);
    }
+#ifdef __cplusplus
+}
+#endif