src/libpspp/copyleft.c: Add copyright and licence notice and an explanitory comment.
[pspp] / src / libpspp / array.c
index f37270c81da9796320de8507cb097a80ceca6869..376bd681dbfa586807c160908cd74b2adb4dd325 100644 (file)
@@ -89,6 +89,7 @@
 
 #include <limits.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include "libpspp/assertion.h"
 
@@ -1027,3 +1028,18 @@ is_heap (const void *array, size_t count, size_t size,
   return true;
 }
 
+/* Reverses the order of ARRAY, which contains COUNT elements of SIZE bytes
+   each. */
+void
+reverse_array (void *array_, size_t count, size_t size)
+{
+  uint8_t *array = array_;
+  uint8_t *first = array;
+  uint8_t *last = array + (count - 1) * size;
+  for (size_t i = 0; i < count / 2; i++)
+    {
+      swap (first, last, size);
+      first += size;
+      last -= size;
+    }
+}