summaryrefslogtreecommitdiff
path: root/liboil/ref
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2005-12-16 07:56:55 +0000
committerDavid Schleef <ds@schleef.org>2005-12-16 07:56:55 +0000
commit34412095f09c51a2b6a764b7a7983340055ee6a4 (patch)
treec2f12da08041a08438edfbb11e917b247377a970 /liboil/ref
parent91ca647a4aa22f6f68209f156ffeb361a4610c9b (diff)
downloadliboil-34412095f09c51a2b6a764b7a7983340055ee6a4.tar.gz
* liboil/c/swab.c: swabbing functions
* liboil/liboilclasses.h: * liboil/liboilfuncs.h: * liboil/ref/copy.c: some new classes.
Diffstat (limited to 'liboil/ref')
-rw-r--r--liboil/ref/copy.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/liboil/ref/copy.c b/liboil/ref/copy.c
index 8b79fe4..e710226 100644
--- a/liboil/ref/copy.c
+++ b/liboil/ref/copy.c
@@ -60,3 +60,62 @@ copy_u8_ref (uint8_t *dest, uint8_t *src, int n)
}
OIL_DEFINE_IMPL_REF (copy_u8_ref, copy_u8);
+/**
+ * oil_compare_u8:
+ * @d_1: destination array
+ * @s1: source array
+ * @s2: source array
+ * @n: number of elements
+ *
+ * Compares two arrays. The index of the first two elements that are
+ * unequal is written into dest. If all elements are equal, @n is
+ * written into dest.
+ */
+OIL_DEFINE_CLASS (compare_u8, "uint32_t *d_1, uint8_t *s1, uint8_t *s2, int n");
+
+static void
+compare_u8_ref (uint32_t *dest, uint8_t *src1, uint8_t *src2, int n)
+{
+ int i;
+
+ for(i=0;i<n;i++){
+ if (src1[i] != src2[i]) {
+ dest[0] = i;
+ return;
+ }
+ }
+ dest[0] = n;
+}
+OIL_DEFINE_IMPL_REF (compare_u8_ref, compare_u8);
+
+/**
+ * oil_testzero_u8:
+ * @d_1: destination array
+ * @s: source array
+ * @n: number of elements
+ *
+ * Tests each element in the source array for equality with 0. The
+ * index of the first zero element is written into dest. If all
+ * elements are non-zero, @n is written into dest.
+ *
+ * This function is roughly equivalent to strnlen(). One notably
+ * difference is that implementations of this function may legally
+ * read past the end of the string.
+ */
+OIL_DEFINE_CLASS (testzero_u8, "uint32_t *d_1, uint8_t *s, int n");
+
+static void
+testzero_u8_ref (uint32_t *dest, uint8_t *src1, int n)
+{
+ int i;
+
+ for(i=0;i<n;i++){
+ if (src1[i] == 0) {
+ dest[0] = i;
+ return;
+ }
+ }
+ dest[0] = n;
+}
+OIL_DEFINE_IMPL_REF (testzero_u8_ref, testzero_u8);
+