Quellcode durchsuchen

misc/balloc.h: add BRealloc()

ambrop7 vor 13 Jahren
Ursprung
Commit
e4cb194e9c
1 geänderte Dateien mit 21 neuen und 0 gelöschten Zeilen
  1. 21 0
      misc/balloc.h

+ 21 - 0
misc/balloc.h

@@ -61,6 +61,18 @@ static void * BAlloc (size_t bytes);
  */
 static void BFree (void *m);
 
+/**
+ * Changes the size of a memory block. On success, the memory block
+ * may be moved to a different address.
+ * 
+ * @param m pointer to a memory block obtained from {@link BAlloc}
+ *          or other functions in this group. If this is NULL, the
+ *          call is equivalent to {@link BAlloc}(bytes).
+ * @param bytes new size of the memory block
+ * @return new pointer to the memory block, or NULL on failure
+ */
+static void * BRealloc (void *m, size_t bytes);
+
 /**
  * Allocates memory, with size given as a {@link bsize_t}.
  * 
@@ -146,6 +158,15 @@ void BFree (void *m)
     free(m);
 }
 
+void * BRealloc (void *m, size_t bytes)
+{
+    if (bytes == 0) {
+        return realloc(m, 1);
+    }
+    
+    return realloc(m, bytes);
+}
+
 void * BAllocSize (bsize_t bytes)
 {
     if (bytes.is_overflow) {