aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-11-25 14:17:49 +0100
committerMattias Andrée <maandree@kth.se>2018-11-25 14:17:49 +0100
commite2dc7cf9c966d4c94b7556c1c2ada8d170715654 (patch)
tree78733ab53fb0e1d185773d23f0f5ccd373be2bc1
parentAdd man pages (diff)
downloadlibsimple-e2dc7cf9c966d4c94b7556c1c2ada8d170715654.tar.gz
libsimple-e2dc7cf9c966d4c94b7556c1c2ada8d170715654.tar.bz2
libsimple-e2dc7cf9c966d4c94b7556c1c2ada8d170715654.tar.xz
Fix consistence in memelem functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libsimple/mem.h8
-rw-r--r--libsimple/memelem.h204
-rw-r--r--libsimple/str.h4
-rw-r--r--libsimple/strn.h4
-rw-r--r--man3/libsimple_memelem.314
-rw-r--r--man3/libsimple_memelem_inv.314
-rw-r--r--man3/libsimple_memelemscan.316
-rw-r--r--man3/libsimple_memelemscan_inv.316
-rw-r--r--man3/libsimple_mempsetelem.38
-rw-r--r--man3/libsimple_memrelem.314
-rw-r--r--man3/libsimple_memrelem_inv.314
-rw-r--r--man3/libsimple_memreplaceelem.32
-rw-r--r--man3/libsimple_memsetelem.36
-rw-r--r--man3/libsimple_rawmemelem.312
-rw-r--r--man3/libsimple_rawmemelem_inv.312
-rw-r--r--man3/libsimple_rawmemrelem.314
-rw-r--r--man3/libsimple_rawmemrelem_inv.314
-rw-r--r--memelem.c68
-rw-r--r--memelem_inv.c84
-rw-r--r--memelemmove.c24
-rw-r--r--memelemscan.c68
-rw-r--r--memelemscan_inv.c84
-rw-r--r--mempsetelem.c16
-rw-r--r--memrelem.c70
-rw-r--r--memrelem_inv.c112
-rw-r--r--memreplaceelem.c34
-rw-r--r--rawmemelem.c8
-rw-r--r--rawmemelem_inv.c8
-rw-r--r--rawmemelemcpy.c18
-rw-r--r--rawmemelemmove.c24
-rw-r--r--rawmemrelem.c40
-rw-r--r--rawmemrelem_inv.c96
32 files changed, 565 insertions, 565 deletions
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 61df6bc..f477681 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -516,7 +516,7 @@ int libsimple_memcaseends(const void *, size_t, const void *, size_t);
* @return 1 if the arrays are equal, 0 otherwise
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-int libsimple_memcasecmp(const void *__a, const void *__b, size_t __n);
+int libsimple_memcasecmp(const void *, const void *, size_t);
#ifndef memcasecmp
# define memcasecmp libsimple_memcasecmp
#endif
@@ -636,7 +636,7 @@ libsimple_rawmemccpy(void *restrict __d_, const void *restrict __s_, int __c_) /
* be found within the first `n` bytes of `s` (before
* copying), `NULL` otherwise
*/
-void *libsimple_memcmove(void *__d_, const void *__s_, int __c_, size_t __n);
+void *libsimple_memcmove(void *, const void *, int, size_t);
#ifndef memcmove
# define memcmove libsimple_memcmove
#endif
@@ -717,7 +717,7 @@ libsimple_memreplace(void *__s_, int __old_, int __new_, size_t __n)
* @param n The number of bytes to copy or covert
* @return `&d[n]`
*/
-void *libsimple_memptolower(void *__d, const void *__s, size_t __n);
+void *libsimple_memptolower(void *, const void *, size_t);
#ifndef memptolower
# define memptolower libsimple_memptolower
#endif
@@ -736,7 +736,7 @@ void *libsimple_memptolower(void *__d, const void *__s, size_t __n);
* @param n The number of bytes to copy or covert
* @return `&d[n]`
*/
-void *libsimple_memptoupper(void *__d, const void *__s, size_t __n);
+void *libsimple_memptoupper(void *, const void *, size_t);
#ifndef memptoupper
# define memptoupper libsimple_memptoupper
#endif
diff --git a/libsimple/memelem.h b/libsimple/memelem.h
index 4533db8..29570f6 100644
--- a/libsimple/memelem.h
+++ b/libsimple/memelem.h
@@ -4,17 +4,17 @@
/**
* Finds the first element in an array, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to search for
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a minimal offset such that,
- * `!memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
+ * `!memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
* `NULL` if no such offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memelem(const void *, size_t, const void *, size_t);
+void *libsimple_memelem(const void *, const void *, size_t, size_t);
#ifndef memelem
# define memelem libsimple_memelem
#endif
@@ -28,12 +28,12 @@ void *libsimple_memelem(const void *, size_t, const void *, size_t);
* occurence of the specified value in the specified array, its
* behaviour is undefined
*
- * @param haystack The array of bytes to search
+ * @param haystack The array to search
* @param needle The substring to search for
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
* @return `haystack` with a minimal offset such that,
- * `!memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`
+ * `!memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__)))
void *libsimple_rawmemelem(const void *, const void *, size_t);
@@ -45,18 +45,18 @@ void *libsimple_rawmemelem(const void *, const void *, size_t);
/**
* Finds the first element in an array, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to search for
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a minimal offset such that,
- * `!memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
- * `(void *)&((char *)haystack)[nhaystack * nneedle]`
- * if no such offset exists
+ * `!memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
+ * `(void *)&((char *)haystack)[n * width]` if no such
+ * offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memelemscan(const void *, size_t, const void *, size_t);
+void *libsimple_memelemscan(const void *, const void *, size_t, size_t);
#ifndef memelemscan
# define memelemscan libsimple_memelemscan
#endif
@@ -65,17 +65,17 @@ void *libsimple_memelemscan(const void *, size_t, const void *, size_t);
/**
* Finds the last element in an array, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to search for
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a maximal offset such that,
- * `!memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
+ * `!memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
* `NULL` if no such offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memrelem(const void *, size_t, const void *, size_t);
+void *libsimple_memrelem(const void *, const void *, size_t, size_t);
#ifndef memrelem
# define memrelem libsimple_memrelem
#endif
@@ -89,16 +89,16 @@ void *libsimple_memrelem(const void *, size_t, const void *, size_t);
* occurence of the specified value in the specified array, its
* behaviour is undefined
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to search for
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a maximal offset such that,
- * `!memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`
+ * `!memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__)))
-void *libsimple_rawmemrelem(const void *, size_t, const void *, size_t);
+void *libsimple_rawmemrelem(const void *, const void *, size_t, size_t);
#ifndef rawmemrelem
# define rawmemrelem libsimple_rawmemrelem
#endif
@@ -108,17 +108,17 @@ void *libsimple_rawmemrelem(const void *, size_t, const void *, size_t);
* Finds the first element in an array that is different from
* the specified element, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to skip over
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a minimal offset such that,
- * `memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
+ * `memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
* `NULL` if no such offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memelem_inv(const void *, size_t, const void *, size_t);
+void *libsimple_memelem_inv(const void *, const void *, size_t, size_t);
#ifndef memelem_inv
# define memelem_inv libsimple_memelem_inv
#endif
@@ -133,12 +133,12 @@ void *libsimple_memelem_inv(const void *, size_t, const void *, size_t);
* occurence of any value other than the specified value in the
* specified array, its behaviour is undefined
*
- * @param haystack The array of bytes to search
+ * @param haystack The array to search
+ * @param width The size of `needle` and each element in `haystack`
* @param needle The substring to skip over
- * @param nneedle The length of `needle`
* @return `haystack` with a minimal offset such that,
- * `memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`
+ * `memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__)))
void *libsimple_rawmemelem_inv(const void *, const void *, size_t);
@@ -151,18 +151,18 @@ void *libsimple_rawmemelem_inv(const void *, const void *, size_t);
* Finds the first element in an array that is different from
* the specified element, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to skip over
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a minimal offset such that,
- * `memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
- * `(void *)&((char *)haystack)[nhaystack * nneedle]`
- * if no such offset exists
+ * `memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
+ * `(void *)&((char *)haystack)[n * width]` if no such
+ * offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memelemscan_inv(const void *, size_t, const void *, size_t);
+void *libsimple_memelemscan_inv(const void *, const void *, size_t, size_t);
#ifndef memelemscan_inv
# define memelemscan_inv libsimple_memelemscan_inv
#endif
@@ -172,17 +172,17 @@ void *libsimple_memelemscan_inv(const void *, size_t, const void *, size_t);
* Finds the last element in an array that is different from
* the specified element, the comparison is case-sensitive
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to skip over
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a maximal offset such that,
- * `memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`,
+ * `memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`,
* `NULL` if no such offset exists
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-void *libsimple_memrelem_inv(const void *, size_t, const void *, size_t);
+void *libsimple_memrelem_inv(const void *, const void *, size_t, size_t);
#ifndef memrelem_inv
# define memrelem_inv libsimple_memrelem_inv
#endif
@@ -197,16 +197,16 @@ void *libsimple_memrelem_inv(const void *, size_t, const void *, size_t);
* occurence of any value other than the specified value in the
* specified array, its behaviour is undefined
*
- * @param haystack The array of bytes to search
- * @param nhaystack The length of `haystack`, divided by `needle`
+ * @param haystack The array to search
* @param needle The substring to skip over
- * @param nneedle The length of `needle`
+ * @param width The size of `needle` and each element in `haystack`
+ * @param n The number of elements in `haystack`
* @return `haystack` with a maximal offset such that,
- * `memcmp(r, needle, nneedle)` where `r` is the
- * returned pointer and such that `(r - haystack) % nneedle == 0`
+ * `memcmp(r, needle, width)` where `r` is the returned
+ * pointer and such that `(r - haystack) % width == 0`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __returns_nonnull__, __warn_unused_result__)))
-void *libsimple_rawmemrelem_inv(const void *, size_t, const void *, size_t);
+void *libsimple_rawmemrelem_inv(const void *, const void *, size_t, size_t);
#ifndef rawmemrelem_inv
# define rawmemrelem_inv libsimple_rawmemrelem_inv
#endif
@@ -215,14 +215,14 @@ void *libsimple_rawmemrelem_inv(const void *, size_t, const void *, size_t);
/**
* Fills an array with a number of copies of an item
*
- * @param buf The array to fill
- * @param item The element to fill `buf` with
- * @param size The size of `item`
- * @param nitems The number of copies to fill `buf` with
- * @return `&buf[nelems * size]`
+ * @param buf The array to fill
+ * @param item The element to fill `buf` with
+ * @param width The size of `item`
+ * @param n The number of copies to fill `buf` with
+ * @return `&buf[n * width]`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
-void *libsimple_mempsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems);
+void *libsimple_mempsetelem(void *, const void *, size_t, size_t);
#ifndef mempsetelem
# define mempsetelem libsimple_mempsetelem
#endif
@@ -233,13 +233,13 @@ void *libsimple_mempsetelem(void *__buf, const void *__item, size_t __size, size
*
* @param buf The array to fill
* @param item The element to fill `buf` with
- * @param size The size of `item`
- * @param nitems The number of copies to fill `buf` with
+ * @param width The size of `item`
+ * @param n The number of copies to fill `buf` with
* @return `buf`
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
-static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __size, size_t __nitems)
-{ return __item = libsimple_mempsetelem(__buf, __item, __size, __nitems), __buf; }
+static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t __width, size_t __n)
+{ return __item = libsimple_mempsetelem(__buf, __item, __width, __n), __buf; }
#ifndef memsetelem
# define memsetelem libsimple_memsetelem
#endif
@@ -248,16 +248,16 @@ static inline void *libsimple_memsetelem(void *__buf, const void *__item, size_t
/**
* Copy elements in an array to another array, but stop after a specific element
*
- * @param d The location the array shall be copied to
- * @param s The array to copy
- * @param elem The element that stops the copying
- * @param size The size of each element
- * @param n The maximum number of elements to copy
- * @return `&rawmemelem(d, c, size)[size]` (after copying) if `elem`
- * can be found within the first `n` elements of `s` (before
- * copying), `NULL` otherwise
+ * @param d The location the array shall be copied to
+ * @param s The array to copy
+ * @param elem The element that stops the copying
+ * @param width The size of each element
+ * @param n The maximum number of elements to copy
+ * @return `&rawmemelem(d, c, width)[width]` (after copying) if `elem`
+ * can be found within the first `n` elements of `s` (before
+ * copying), `NULL` otherwise
*/
-void *libsimple_memelemcpy(void *restrict __d, const void *restrict __s, const void *restrict __elem, size_t __size, size_t __n);
+void *libsimple_memelemcpy(void *restrict, const void *restrict, const void *restrict, size_t, size_t);
#ifndef memelemcpy
# define memelemcpy libsimple_memelemcpy
#endif
@@ -266,16 +266,16 @@ void *libsimple_memelemcpy(void *restrict __d, const void *restrict __s, const v
/**
* Move elements in an array, but stop after a specific element
*
- * @param d The location the array shall be copied to
- * @param s The array to copy
- * @param elem The element that stops the copying
- * @param size The size of each element
- * @param n The maximum number of elements to copy
- * @return `&rawmemelem(d, c, size)[size]` (after copying) if `elem`
- * can be found within the first `n` elements of `s` (before
- * copying), `NULL` otherwise
+ * @param d The location the array shall be copied to
+ * @param s The array to copy
+ * @param elem The element that stops the copying
+ * @param width The size of each element
+ * @param n The maximum number of elements to copy
+ * @return `&rawmemelem(d, c, width)[width]` (after copying) if `elem`
+ * can be found within the first `n` elements of `s` (before
+ * copying), `NULL` otherwise
*/
-void *libsimple_memelemmove(void *__d, const void *__s, const void *restrict __elem, size_t __size, size_t __n);
+void *libsimple_memelemmove(void *, const void *, const void *restrict, size_t, size_t);
#ifndef memelemmove
# define memelemmove libsimple_memelemmove
#endif
@@ -289,13 +289,13 @@ void *libsimple_memelemmove(void *__d, const void *__s, const void *restrict __e
* occurence of the specified value in the specified array, its
* behaviour is undefined
*
- * @param d The location the array shall be copied to
- * @param s The array to copy
- * @param elem The element that stops the copying
- * @param size The size of each element
- * @return `&rawmemelem(d, c, size)[size]` (after copying)
+ * @param d The location the array shall be copied to
+ * @param s The array to copy
+ * @param elem The element that stops the copying
+ * @param width The size of each element
+ * @return `&rawmemelem(d, c, width)[width]` (after copying)
*/
-void *libsimple_rawmemelemcpy(void *restrict __d, const void *restrict __s, const void *restrict __elem, size_t __size);
+void *libsimple_rawmemelemcpy(void *restrict, const void *restrict, const void *restrict, size_t);
#ifndef rawmemelemcpy
# define rawmemelemcpy libsimple_rawmemelemcpy
#endif
@@ -309,13 +309,13 @@ void *libsimple_rawmemelemcpy(void *restrict __d, const void *restrict __s, cons
* occurence of the specified value in the specified array, its
* behaviour is undefined
*
- * @param d The location the array shall be copied to
- * @param s The array to copy
- * @param elem The element that stops the copying
- * @param size The size of each element
- * @return `&rawmemelem(d, c, size)[size]` (after copying)
+ * @param d The location the array shall be copied to
+ * @param s The array to copy
+ * @param elem The element that stops the copying
+ * @param width The size of each element
+ * @return `&rawmemelem(d, c, width)[width]` (after copying)
*/
-void *libsimple_rawmemelemmove(void *__d, const void *__s, const void *restrict __elem, size_t __size);
+void *libsimple_rawmemelemmove(void *, const void *, const void *restrict, size_t);
#ifndef rawmemelemmove
# define rawmemelemmove libsimple_rawmemelemmove
#endif
@@ -328,11 +328,11 @@ void *libsimple_rawmemelemmove(void *__d, const void *__s, const void *restrict
* @param s The array
* @param old The value of the elements to replace
* @param new The value to replace the elements with
- * @param n The length of `s`, measured in elements
* @param width The size of each element
+ * @param n The length of `s`, measured in elements
* @return `(void *)&((char *)s)[n * width]`
*/
-void *libsimple_memreplaceelem(void *restrict __s_, const void *__old_, const void *__new_, size_t __n, size_t __width);
+void *libsimple_memreplaceelem(void *restrict, const void *, const void *, size_t, size_t);
#ifndef memreplaceelem
# define memreplaceelem libsimple_memreplaceelem
#endif
diff --git a/libsimple/str.h b/libsimple/str.h
index b7251f5..afa0190 100644
--- a/libsimple/str.h
+++ b/libsimple/str.h
@@ -621,7 +621,7 @@ libsimple_strreplace(char *__s, int __old_, int __new_)
* @return `strchr(d, '\0')` (after copying)
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__)))
-char *libsimple_stptolower(char *__d, const char *__s);
+char *libsimple_stptolower(char *, const char *);
#ifndef stptolower
# define stptolower libsimple_stptolower
#endif
@@ -640,7 +640,7 @@ char *libsimple_stptolower(char *__d, const char *__s);
* @return `strchr(d, '\0')` (after copying)
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__)))
-char *libsimple_stptoupper(char *__d, const char *__s);
+char *libsimple_stptoupper(char *, const char *);
#ifndef stptoupper
# define stptoupper libsimple_stptoupper
#endif
diff --git a/libsimple/strn.h b/libsimple/strn.h
index 69660ff..370ac8b 100644
--- a/libsimple/strn.h
+++ b/libsimple/strn.h
@@ -707,7 +707,7 @@ libsimple_strnreplace(char *__s, int __old_, int __new_, size_t __n)
* @return `strnchrnul(d, '\0', n)` (after copying)
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__)))
-char *libsimple_stpntolower(char *__d, const char *__s, size_t __n);
+char *libsimple_stpntolower(char *, const char *, size_t);
#ifndef stpntolower
# define stpntolower libsimple_stpntolower
#endif
@@ -727,7 +727,7 @@ char *libsimple_stpntolower(char *__d, const char *__s, size_t __n);
* @return `strnchrnul(d, '\0', n)` (after copying)
*/
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__, __returns_nonnull__)))
-char *libsimple_stpntoupper(char *__d, const char *__s, size_t __n);
+char *libsimple_stpntoupper(char *, const char *, size_t);
#ifndef stpntoupper
# define stpntoupper libsimple_stpntoupper
#endif
diff --git a/man3/libsimple_memelem.3 b/man3/libsimple_memelem.3
index e1189b3..4ccdb3a 100644
--- a/man3/libsimple_memelem.3
+++ b/man3/libsimple_memelem.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMELEM 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMELEM 3 2018-11-25 libsimple
.SH NAME
libsimple_memelem \- find aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memelem(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memelem(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memelem
# define memelem libsimple_memelem
@@ -20,13 +20,13 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the first occurence of the byte string
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The comparison is case-sensitive.
.SH RETURN VALUE
@@ -35,12 +35,12 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR !memcmp(r,needle,nneedle) ,
+.IR !memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
.B NULL
is returned.
diff --git a/man3/libsimple_memelem_inv.3 b/man3/libsimple_memelem_inv.3
index a36e38c..c3b3208 100644
--- a/man3/libsimple_memelem_inv.3
+++ b/man3/libsimple_memelem_inv.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMELEM_INV 3 2018-11-24 libsimple
+.TH LIBSIMPLE_MEMELEM_INV 3 2018-11-25 libsimple
.SH NAME
libsimple_memelem_inv \- find different aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memelem_inv(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memelem_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memelem_inv
# define memelem_inv libsimple_memelem_inv
@@ -20,14 +20,14 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the first occurence of a byte string
different from
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The comparison is case-sensitive.
.SH RETURN VALUE
@@ -36,12 +36,12 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR memcmp(r,needle,nneedle) ,
+.IR memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
.B NULL
is returned.
diff --git a/man3/libsimple_memelemscan.3 b/man3/libsimple_memelemscan.3
index 727c44a..092508e 100644
--- a/man3/libsimple_memelemscan.3
+++ b/man3/libsimple_memelemscan.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMELEMSCAN 3 2018-11-17 libsimple
+.TH LIBSIMPLE_MEMELEMSCAN 3 2018-11-25 libsimple
.SH NAME
libsimple_memelemscan \- find aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memelemscan(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memelemscan(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memelemscan
# define memelemscan libsimple_memelemscan
@@ -20,13 +20,13 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the first occurence of the byte string
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such character exist in the memory
segment, the memory segment's end is returned.
.PP
@@ -37,14 +37,14 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR !memcmp(r,needle,nneedle) ,
+.IR !memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
-.I (void *)&((char *)haystack)[nhaystack*nneedle]
+.I (void *)&((char *)haystack)[n*width]
is returned.
.SH ERRORS
The
diff --git a/man3/libsimple_memelemscan_inv.3 b/man3/libsimple_memelemscan_inv.3
index 77f7119..3fdd8f8 100644
--- a/man3/libsimple_memelemscan_inv.3
+++ b/man3/libsimple_memelemscan_inv.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMELEMSCAN_INV 3 2018-11-24 libsimple
+.TH LIBSIMPLE_MEMELEMSCAN_INV 3 2018-11-25 libsimple
.SH NAME
libsimple_memelemscan_inv \- skip aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memelemscan_inv(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memelemscan_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memelemscan_inv
# define memelemscan_inv libsimple_memelemscan_inv
@@ -20,14 +20,14 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the first occurence of a byte string
different from
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such character exist in the memory
segment, the memory segment's end is returned.
.PP
@@ -38,14 +38,14 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR memcmp(r,needle,nneedle) ,
+.IR memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
-.I (void *)&((char *)haystack)[nhaystack*nneedle]
+.I (void *)&((char *)haystack)[n*width]
is returned.
.SH ERRORS
The
diff --git a/man3/libsimple_mempsetelem.3 b/man3/libsimple_mempsetelem.3
index 0b32228..e10a252 100644
--- a/man3/libsimple_mempsetelem.3
+++ b/man3/libsimple_mempsetelem.3
@@ -5,7 +5,7 @@ libsimple_mempsetelem \- fill an array with a value
.nf
#include <libsimple.h>
-void *libsimple_mempsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIsize\fP, size_t \fInitems\fP);
+void *libsimple_mempsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef mempsetelem
# define mempsetelem libsimple_mempsetelem
@@ -20,18 +20,18 @@ The
function fills the beginning of
.I buf
with
-.I nitems
+.I n
copies of the element
.I item
with the size
-.IR size .
+.IR width .
.SH RETURN VALUE
The
.BR libsimple_mempsetelem ()
function returns the pointer
.I buf
with the offset
-.I nitems*size
+.I n*width
(the byte where the copy stopped).
.SH ERRORS
The
diff --git a/man3/libsimple_memrelem.3 b/man3/libsimple_memrelem.3
index f6681e9..26bcfb8 100644
--- a/man3/libsimple_memrelem.3
+++ b/man3/libsimple_memrelem.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMRELEM 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMRELEM 3 2018-11-25 libsimple
.SH NAME
libsimple_memrelem \- find aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memrelem(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memrelem(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memrelem
# define memrelem libsimple_memrelem
@@ -20,13 +20,13 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the last occurence of the byte string
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The comparison is case-sensitive.
.SH RETURN VALUE
@@ -35,12 +35,12 @@ The
function returns the pointer
.I s
with a maximal offset such that
-.IR !memcmp(r,needle,nneedle) ,
+.IR !memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
.B NULL
is returned.
diff --git a/man3/libsimple_memrelem_inv.3 b/man3/libsimple_memrelem_inv.3
index 02b4be7..f3d5736 100644
--- a/man3/libsimple_memrelem_inv.3
+++ b/man3/libsimple_memrelem_inv.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_MEMRELEM_INV 3 2018-11-24 libsimple
+.TH LIBSIMPLE_MEMRELEM_INV 3 2018-11-25 libsimple
.SH NAME
libsimple_memrelem_inv \- find different aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_memrelem_inv(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_memrelem_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memrelem_inv
# define memrelem_inv libsimple_memrelem_inv
@@ -20,14 +20,14 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the last occurence of a byte string
different from
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The comparison is case-sensitive.
.SH RETURN VALUE
@@ -36,12 +36,12 @@ The
function returns the pointer
.I s
with a maximal offset such that
-.IR memcmp(r,needle,nneedle) ,
+.IR memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists,
.B NULL
is returned.
diff --git a/man3/libsimple_memreplaceelem.3 b/man3/libsimple_memreplaceelem.3
index 02e0f06..6ad5c6c 100644
--- a/man3/libsimple_memreplaceelem.3
+++ b/man3/libsimple_memreplaceelem.3
@@ -5,7 +5,7 @@ libsimple_memreplaceelem \- replace elements in an array
.nf
#include <libsimple.h>
-void *libsimple_memreplaceelem(void *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIn\fP, size_t \fIwidth\fP);
+void *libsimple_memreplaceelem(void *\fIs\fP, int \fIold\fP, int \fInew\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memreplaceelem
# define memreplaceelem libsimple_memreplaceelem
diff --git a/man3/libsimple_memsetelem.3 b/man3/libsimple_memsetelem.3
index 516a20b..91e5b63 100644
--- a/man3/libsimple_memsetelem.3
+++ b/man3/libsimple_memsetelem.3
@@ -5,7 +5,7 @@ libsimple_memsetelem \- fill an array with a value
.nf
#include <libsimple.h>
-static inline void *libsimple_memsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIsize\fP, size_t \fInitems\fP);
+static inline void *libsimple_memsetelem(void *\fIbuf\fP, const void *\fIitem\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef memsetelem
# define memsetelem libsimple_memsetelem
@@ -20,11 +20,11 @@ The
function fills the beginning of
.I buf
with
-.I nitems
+.I n
copies of the element
.I item
with the size
-.IR size .
+.IR width .
.SH RETURN VALUE
The
.BR libsimple_memsetelem ()
diff --git a/man3/libsimple_rawmemelem.3 b/man3/libsimple_rawmemelem.3
index 4e83ed0..62c986c 100644
--- a/man3/libsimple_rawmemelem.3
+++ b/man3/libsimple_rawmemelem.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_RAWMEMELEM 3 2018-11-24 libsimple
+.TH LIBSIMPLE_RAWMEMELEM 3 2018-11-25 libsimple
.SH NAME
libsimple_rawmemelem \- find aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_rawmemelem(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_rawmemelem(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP);
#ifndef rawmemelem
# define rawmemelem libsimple_rawmemelem
@@ -22,9 +22,9 @@ function scans the memory segment
for the first occurence of the byte string
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The
.BR libsimple_rawmemelem ()
@@ -39,12 +39,12 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR !memcmp(r,needle,nneedle) ,
+.IR !memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists, the behaviour is undefined.
.SH ERRORS
The
diff --git a/man3/libsimple_rawmemelem_inv.3 b/man3/libsimple_rawmemelem_inv.3
index 20ed595..28e5bef 100644
--- a/man3/libsimple_rawmemelem_inv.3
+++ b/man3/libsimple_rawmemelem_inv.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_RAWMEMELEM_INV 3 2018-11-24 libsimple
+.TH LIBSIMPLE_RAWMEMELEM_INV 3 2018-11-25 libsimple
.SH NAME
libsimple_rawmemelem_inv \- find different aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_rawmemelem_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_rawmemelem_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP);
#ifndef rawmemelem_inv
# define rawmemelem_inv libsimple_rawmemelem_inv
@@ -23,9 +23,9 @@ for the first occurence of a byte string
different from
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
.PP
The
.BR libsimple_rawmemchr ()
@@ -40,12 +40,12 @@ The
function returns the pointer
.I s
with a minimal offset such that
-.IR memcmp(r,needle,nneedle) ,
+.IR memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists, the behaviour is undefined.
.SH ERRORS
The
diff --git a/man3/libsimple_rawmemrelem.3 b/man3/libsimple_rawmemrelem.3
index 0a179a8..4ac85aa 100644
--- a/man3/libsimple_rawmemrelem.3
+++ b/man3/libsimple_rawmemrelem.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_RAWMEMRELEM 3 2018-11-24 libsimple
+.TH LIBSIMPLE_RAWMEMRELEM 3 2018-11-25 libsimple
.SH NAME
libsimple_rawmemrelem \- find aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_rawmemrelem(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_rawmemrelem(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef rawmemrelem
# define rawmemrelem libsimple_rawmemrelem
@@ -20,13 +20,13 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the last occurence of the byte string
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
The
.BR libsimple_rawmemrelem ()
function assumes there is at least one
@@ -40,12 +40,12 @@ The
function returns the pointer
.I s
with a maximal offset such that
-.IR !memcmp(r,needle,nneedle) ,
+.IR !memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists, the behaviour is undefined.
.SH ERRORS
The
diff --git a/man3/libsimple_rawmemrelem_inv.3 b/man3/libsimple_rawmemrelem_inv.3
index d2d1acf..ee16eb9 100644
--- a/man3/libsimple_rawmemrelem_inv.3
+++ b/man3/libsimple_rawmemrelem_inv.3
@@ -1,11 +1,11 @@
-.TH LIBSIMPLE_RAWMEMRELEM_INV 3 2018-11-24 libsimple
+.TH LIBSIMPLE_RAWMEMRELEM_INV 3 2018-11-25 libsimple
.SH NAME
libsimple_rawmemrelem_inv \- find different aligned byte string in memory
.SH SYNOPSIS
.nf
#include <libsimple.h>
-void *libsimple_rawmemrelem_inv(const void *\fIhaystack\fP, size_t \fInhaystack\fP, const void *\fIneedle\fP, size_t \fInneedle\fP);
+void *libsimple_rawmemrelem_inv(const void *\fIhaystack\fP, const void *\fIneedle\fP, size_t \fIwidth\fP, size_t \fIn\fP);
#ifndef rawmemrelem_inv
# define rawmemrelem_inv libsimple_rawmemrelem_inv
@@ -20,14 +20,14 @@ The
function scans the memory segment
.IR haystack ,
with the size
-.IR nhaystack*nneedle ,
+.IR n*width ,
for the last occurence of a byte string
different from
.I needle
with the size
-.IR nneedle ,
+.IR width ,
and with an offset equivalent to zero modulo
-.IR nneedle .
+.IR width .
The
.BR libsimple_rawmemrelem_inv ()
function assumes there is at least one
@@ -41,12 +41,12 @@ The
function returns the pointer
.I s
with a maximal offset such that
-.IR memcmp(r,needle,nneedle) ,
+.IR memcmp(r,needle,width) ,
where
.I r
is the returned pointer, and such that
the offset is equivalent to zero modulo
-.IR nneedle .
+.IR width .
If no such offset exists, the behaviour is undefined.
.SH ERRORS
The
diff --git a/memelem.c b/memelem.c
index 29d6ed9..7d9231d 100644
--- a/memelem.c
+++ b/memelem.c
@@ -4,18 +4,18 @@
void *
-libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memelem(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
- return memchr(hay_, *(char *)sub_, hayn);
+ return memchr(hay_, *(char *)sub_, n);
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay == sub)
return hay;
break;
@@ -24,7 +24,7 @@ libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay == sub)
return hay;
break;
@@ -33,7 +33,7 @@ libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay == sub)
return hay;
break;
@@ -43,8 +43,8 @@ libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (; hayn--; hay += subn) {
- for (i = 0; i < subn; i++)
+ for (; n--; hay += width) {
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
goto next;
return hay;
@@ -64,38 +64,38 @@ libsimple_memelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
int
main(void)
{
- assert(!strcmpnul(libsimple_memelem("12345634", 8, "", 0), "12345634"));
- assert(!strcmpnul(libsimple_memelem("12345634", 0, "", 0), "12345634"));
+ assert(!strcmpnul(libsimple_memelem("12345634", "", 0, 8), "12345634"));
+ assert(!strcmpnul(libsimple_memelem("12345634", "", 0, 0), "12345634"));
- assert(!strcmpnul(libsimple_memelem("12345634", 8, "3", 1), "345634"));
- assert(!libsimple_memelem("12345634", 8, "x", 1));
- assert(!strcmpnul(libsimple_memelem("13456342", 8, "3", 1), "3456342"));
- assert(!libsimple_memelem("12345634", 0, "3", 1));
+ assert(!strcmpnul(libsimple_memelem("12345634", "3", 1, 8), "345634"));
+ assert(!libsimple_memelem("12345634", "x", 1, 8));
+ assert(!strcmpnul(libsimple_memelem("13456342", "3", 1, 8), "3456342"));
+ assert(!libsimple_memelem("12345634", "3", 1, 0));
- assert(!strcmpnul(libsimple_memelem("12345634", 4, "34", 2), "345634"));
- assert(!libsimple_memelem("12345634", 4, "xx", 2));
- assert(!libsimple_memelem("13456342", 4, "34", 2));
- assert(!libsimple_memelem("12345634", 0, "34", 2));
+ assert(!strcmpnul(libsimple_memelem("12345634", "34", 2, 4), "345634"));
+ assert(!libsimple_memelem("12345634", "xx", 2, 4));
+ assert(!libsimple_memelem("13456342", "34", 2, 4));
+ assert(!libsimple_memelem("12345634", "34", 2, 0));
- assert(!strcmpnul(libsimple_memelem("abcd1234abcd1234", 4, "1234", 4), "1234abcd1234"));
- assert(!libsimple_memelem("abcd1234abcd1234", 4, "zzzz", 4));
- assert(!libsimple_memelem("cd1234abcd1234ab", 4, "1234", 4));
- assert(!libsimple_memelem("abcd1234abcd1234", 0, "1234", 4));
+ assert(!strcmpnul(libsimple_memelem("abcd1234abcd1234", "1234", 4, 4), "1234abcd1234"));
+ assert(!libsimple_memelem("abcd1234abcd1234", "zzzz", 4, 4));
+ assert(!libsimple_memelem("cd1234abcd1234ab", "1234", 4, 4));
+ assert(!libsimple_memelem("abcd1234abcd1234", "1234", 4, 0));
- assert(!strcmpnul(libsimple_memelem("abcdefgh12345678abcdefgh12345678", 4, "12345678", 8), "12345678abcdefgh12345678"));
- assert(!libsimple_memelem("abcdefgh12345678abcdefgh12345678", 4, "zzzzzzzz", 8));
- assert(!libsimple_memelem("efgh12345678abcdefgh12345678abcd", 4, "12345678", 8));
- assert(!libsimple_memelem("abcdefgh12345678abcdefgh12345678", 0, "12345678", 8));
+ assert(!strcmpnul(libsimple_memelem("abcdefgh12345678abcdefgh12345678", "12345678", 8, 4), "12345678abcdefgh12345678"));
+ assert(!libsimple_memelem("abcdefgh12345678abcdefgh12345678", "zzzzzzzz", 8, 4));
+ assert(!libsimple_memelem("efgh12345678abcdefgh12345678abcd", "12345678", 8, 4));
+ assert(!libsimple_memelem("abcdefgh12345678abcdefgh12345678", "12345678", 8, 0));
- assert(!strcmpnul(libsimple_memelem("abc123abc123", 4, "123", 3), "123abc123"));
- assert(!libsimple_memelem("abc123abc123", 4, "zzz", 3));
- assert(!libsimple_memelem("bc123abc123a", 4, "123", 3));
- assert(!libsimple_memelem("abc123abc123", 0, "123", 3));
+ assert(!strcmpnul(libsimple_memelem("abc123abc123", "123", 3, 4), "123abc123"));
+ assert(!libsimple_memelem("abc123abc123", "zzz", 3, 4));
+ assert(!libsimple_memelem("bc123abc123a", "123", 3, 4));
+ assert(!libsimple_memelem("abc123abc123", "123", 3, 0));
- assert(!strcmpnul(libsimple_memelem("-a-aa--a", 4, "a-", 2), "a--a"));
- assert(!strcmpnul(libsimple_memelem("--a--aa----a", 4, "a--", 3), "a----a"));
- assert(!strcmpnul(libsimple_memelem("---a---aa------a", 4, "a---", 4), "a------a"));
- assert(!strcmpnul(libsimple_memelem("-------a-------aa--------------a", 4, "a-------", 8), "a--------------a"));
+ assert(!strcmpnul(libsimple_memelem("-a-aa--a", "a-", 2, 4), "a--a"));
+ assert(!strcmpnul(libsimple_memelem("--a--aa----a", "a--", 3, 4), "a----a"));
+ assert(!strcmpnul(libsimple_memelem("---a---aa------a", "a---", 4, 4), "a------a"));
+ assert(!strcmpnul(libsimple_memelem("-------a-------aa--------------a", "a-------", 8, 4), "a--------------a"));
return 0;
}
diff --git a/memelem_inv.c b/memelem_inv.c
index 5c3153d..dace2d4 100644
--- a/memelem_inv.c
+++ b/memelem_inv.c
@@ -4,18 +4,18 @@
void *
-libsimple_memelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memelem_inv(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return NULL;
case 1:
- return libsimple_memchr_inv(hay_, *(char *)sub_, hayn);
+ return libsimple_memchr_inv(hay_, *(char *)sub_, n);
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay != sub)
return hay;
break;
@@ -24,7 +24,7 @@ libsimple_memelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t su
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay != sub)
return hay;
break;
@@ -33,7 +33,7 @@ libsimple_memelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t su
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (; hayn--; hay++)
+ for (; n--; hay++)
if (*hay != sub)
return hay;
break;
@@ -43,8 +43,8 @@ libsimple_memelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t su
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (; hayn--; hay += subn) {
- for (i = 0; i < subn; i++)
+ for (; n--; hay += width) {
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
return hay;
}
@@ -62,48 +62,48 @@ libsimple_memelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t su
int
main(void)
{
- assert(!strcmpnul(libsimple_memelem_inv("xxoxx", 5, "x", 0), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("xxXxx", 5, "x", 0), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("XXoxx", 5, "x", 0), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("zzzzz", 5, "z", 0), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("zzzzx", 4, "z", 0), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("xxoxx", "x", 0, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("xxXxx", "x", 0, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("XXoxx", "x", 0, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("zzzzz", "z", 0, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("zzzzx", "z", 0, 4), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("xxoxx", 5, "x", 1), "oxx"));
- assert(!strcmpnul(libsimple_memelem_inv("xxXxx", 5, "x", 1), "Xxx"));
- assert(!strcmpnul(libsimple_memelem_inv("XXoxx", 5, "x", 1), "XXoxx"));
- assert(!strcmpnul(libsimple_memelem_inv("zzzzz", 5, "z", 1), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("zzzzx", 4, "z", 1), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("xxoxx", "x", 1, 5), "oxx"));
+ assert(!strcmpnul(libsimple_memelem_inv("xxXxx", "x", 1, 5), "Xxx"));
+ assert(!strcmpnul(libsimple_memelem_inv("XXoxx", "x", 1, 5), "XXoxx"));
+ assert(!strcmpnul(libsimple_memelem_inv("zzzzz", "z", 1, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("zzzzx", "z", 1, 4), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("-x-x-o-x-x", 5, "-x", 2), "-o-x-x"));
- assert(!strcmpnul(libsimple_memelem_inv("-x-x-X-x-x", 5, "-x", 2), "-X-x-x"));
- assert(!strcmpnul(libsimple_memelem_inv("-X-X-o-x-x", 5, "-x", 2), "-X-X-o-x-x"));
- assert(!strcmpnul(libsimple_memelem_inv("-z-z-z-z-z", 5, "-z", 2), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("-z-z-z-z-x", 4, "-z", 2), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("---z-z-z-x", 5, "--", 2), "-z-z-z-x"));
+ assert(!strcmpnul(libsimple_memelem_inv("-x-x-o-x-x", "-x", 2, 5), "-o-x-x"));
+ assert(!strcmpnul(libsimple_memelem_inv("-x-x-X-x-x", "-x", 2, 5), "-X-x-x"));
+ assert(!strcmpnul(libsimple_memelem_inv("-X-X-o-x-x", "-x", 2, 5), "-X-X-o-x-x"));
+ assert(!strcmpnul(libsimple_memelem_inv("-z-z-z-z-z", "-z", 2, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("-z-z-z-z-x", "-z", 2, 4), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("---z-z-z-x", "--", 2, 5), "-z-z-z-x"));
- assert(!strcmpnul(libsimple_memelem_inv("--x--x--o--x--x", 5, "--x", 3), "--o--x--x"));
- assert(!strcmpnul(libsimple_memelem_inv("--x--x--X--x--x", 5, "--x", 3), "--X--x--x"));
- assert(!strcmpnul(libsimple_memelem_inv("--X--X--o--x--x", 5, "--x", 3), "--X--X--o--x--x"));
- assert(!strcmpnul(libsimple_memelem_inv("--z--z--z--z--z", 5, "--z", 3), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("--z--z--z--z--x", 4, "--z", 3), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("-----z--z--z--x", 5, "---", 3), "--z--z--z--x"));
+ assert(!strcmpnul(libsimple_memelem_inv("--x--x--o--x--x", "--x", 3, 5), "--o--x--x"));
+ assert(!strcmpnul(libsimple_memelem_inv("--x--x--X--x--x", "--x", 3, 5), "--X--x--x"));
+ assert(!strcmpnul(libsimple_memelem_inv("--X--X--o--x--x", "--x", 3, 5), "--X--X--o--x--x"));
+ assert(!strcmpnul(libsimple_memelem_inv("--z--z--z--z--z", "--z", 3, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("--z--z--z--z--x", "--z", 3, 4), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("-----z--z--z--x", "---", 3, 5), "--z--z--z--x"));
- assert(!strcmpnul(libsimple_memelem_inv("---x---x---o---x---x", 5, "---x", 4), "---o---x---x"));
- assert(!strcmpnul(libsimple_memelem_inv("---x---x---X---x---x", 5, "---x", 4), "---X---x---x"));
- assert(!strcmpnul(libsimple_memelem_inv("---X---X---o---x---x", 5, "---x", 4), "---X---X---o---x---x"));
- assert(!strcmpnul(libsimple_memelem_inv("---z---z---z---z---z", 5, "---z", 4), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("---z---z---z---z---x", 4, "---z", 4), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("-------z---z---z---x", 5, "----", 4), "---z---z---z---x"));
+ assert(!strcmpnul(libsimple_memelem_inv("---x---x---o---x---x", "---x", 4, 5), "---o---x---x"));
+ assert(!strcmpnul(libsimple_memelem_inv("---x---x---X---x---x", "---x", 4, 5), "---X---x---x"));
+ assert(!strcmpnul(libsimple_memelem_inv("---X---X---o---x---x", "---x", 4, 5), "---X---X---o---x---x"));
+ assert(!strcmpnul(libsimple_memelem_inv("---z---z---z---z---z", "---z", 4, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("---z---z---z---z---x", "---z", 4, 4), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("-------z---z---z---x", "----", 4, 5), "---z---z---z---x"));
- assert(!strcmpnul(libsimple_memelem_inv("-------x-------x-------o-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelem_inv("-------x-------x-------o-------x-------x", "-------x", 8, 5),
"-------o-------x-------x"));
- assert(!strcmpnul(libsimple_memelem_inv("-------x-------x-------X-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelem_inv("-------x-------x-------X-------x-------x", "-------x", 8, 5),
"-------X-------x-------x"));
- assert(!strcmpnul(libsimple_memelem_inv("-------X-------X-------o-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelem_inv("-------X-------X-------o-------x-------x", "-------x", 8, 5),
"-------X-------X-------o-------x-------x"));
- assert(!strcmpnul(libsimple_memelem_inv("-------z-------z-------z-------z-------z", 5, "-------z", 8), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("-------z-------z-------z-------z-------x", 4, "-------z", 8), NULL));
- assert(!strcmpnul(libsimple_memelem_inv("---------------z-------z-------z-------x", 5, "--------", 8),
+ assert(!strcmpnul(libsimple_memelem_inv("-------z-------z-------z-------z-------z", "-------z", 8, 5), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("-------z-------z-------z-------z-------x", "-------z", 8, 4), NULL));
+ assert(!strcmpnul(libsimple_memelem_inv("---------------z-------z-------z-------x", "--------", 8, 5),
"-------z-------z-------z-------x"));
return 0;
diff --git a/memelemmove.c b/memelemmove.c
index 90bf2fb..d810ba4 100644
--- a/memelemmove.c
+++ b/memelemmove.c
@@ -50,35 +50,35 @@ memelemmove64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem, s
static char *
-memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t size, size_t n)
+memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t width, size_t n)
{
char *p;
size_t i;
if (d <= s) {
- for (; n; s += size, n--) {
- for (i = 0; i < size; i++)
+ for (; n; s += width, n--) {
+ for (i = 0; i < width; i++)
d[i] = s[i];
- for (i = 0; i < size; i++)
+ for (i = 0; i < width; i++)
if (d[i] != elem[i])
goto next_forwards;
- d += size;
+ d += width;
return d;
next_forwards:
- d += size;
+ d += width;
}
return NULL;
} else {
for (p = *(char **)(void *)&s; n; n--) {
- for (i = 0; i < size; i++)
+ for (i = 0; i < width; i++)
if (p[i] != elem[i])
goto next_backwards;
- p += size;
+ p += width;
n = (size_t)(p - s);
p = &d[n];
goto out_backwards;
next_backwards:
- p += size;
+ p += width;
}
n = (size_t)(p - s);
p = NULL;
@@ -93,9 +93,9 @@ memelemmovex(char *restrict d, const char *restrict s, const char *restrict elem
void *
-libsimple_memelemmove(void *d, const void *s, const void *restrict elem, size_t size, size_t n) /* TODO man */
+libsimple_memelemmove(void *d, const void *s, const void *restrict elem, size_t width, size_t n) /* TODO man */
{
- switch (size) {
+ switch (width) {
case 0:
return d;
case 1:
@@ -107,7 +107,7 @@ libsimple_memelemmove(void *d, const void *s, const void *restrict elem, size_t
case 8:
return memelemmove64(d, s, *(const uint64_t *)elem, n);
default:
- return memelemmovex(d, s, elem, size, n);
+ return memelemmovex(d, s, elem, width, n);
}
}
diff --git a/memelemscan.c b/memelemscan.c
index e713d54..d17297a 100644
--- a/memelemscan.c
+++ b/memelemscan.c
@@ -4,32 +4,32 @@
void *
-libsimple_memelemscan(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memelemscan(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
- return libsimple_memscan(hay_, *(char *)sub_, hayn);
+ return libsimple_memscan(hay_, *(char *)sub_, n);
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (; hayn-- && *hay != sub; hay++);
+ for (; n-- && *hay != sub; hay++);
return hay;
}
case 4:
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (; hayn-- && *hay != sub; hay++);
+ for (; n-- && *hay != sub; hay++);
return hay;
}
case 8:
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (; hayn-- && *hay != sub; hay++);
+ for (; n-- && *hay != sub; hay++);
return hay;
}
default:
@@ -37,8 +37,8 @@ libsimple_memelemscan(const void *hay_, size_t hayn, const void *sub_, size_t su
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (; hayn--; hay += subn) {
- for (i = 0; i < subn; i++)
+ for (; n--; hay += width) {
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
goto next;
return hay;
@@ -56,39 +56,39 @@ libsimple_memelemscan(const void *hay_, size_t hayn, const void *sub_, size_t su
int
main(void)
{
- assert(!strcmpnul(libsimple_memelemscan("12345634", 8, "", 0), "12345634"));
- assert(!strcmpnul(libsimple_memelemscan("12345634", 0, "", 0), "12345634"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "", 0, 8), "12345634"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "", 0, 0), "12345634"));
- assert(!strcmpnul(libsimple_memelemscan("12345634", 8, "3", 1), "345634"));
- assert(!strcmpnul(libsimple_memelemscan("12345634", 8, "x", 1), ""));
- assert(!strcmpnul(libsimple_memelemscan("13456342", 8, "3", 1), "3456342"));
- assert(!strcmpnul(libsimple_memelemscan("12345634", 0, "3", 1), "12345634"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "3", 1, 8), "345634"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "x", 1, 8), ""));
+ assert(!strcmpnul(libsimple_memelemscan("13456342", "3", 1, 8), "3456342"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "3", 1, 0), "12345634"));
- assert(!strcmpnul(libsimple_memelemscan("12345634", 4, "34", 2), "345634"));
- assert(!strcmpnul(libsimple_memelemscan("12345634z", 4, "xx", 2), "z"));
- assert(!strcmpnul(libsimple_memelemscan("13456342z", 4, "34", 2), "z"));
- assert(!strcmpnul(libsimple_memelemscan("12345634z", 0, "34", 2), "12345634z"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634", "34", 2, 4), "345634"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634z", "xx", 2, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("13456342z", "34", 2, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("12345634z", "34", 2, 0), "12345634z"));
- assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234", 4, "1234", 4), "1234abcd1234"));
- assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234z", 4, "zzzz", 4), "z"));
- assert(!strcmpnul(libsimple_memelemscan("cd1234abcd1234abz", 4, "1234", 4), "z"));
- assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234z", 0, "1234", 4), "abcd1234abcd1234z"));
+ assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234", "1234", 4, 4), "1234abcd1234"));
+ assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234z", "zzzz", 4, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("cd1234abcd1234abz", "1234", 4, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("abcd1234abcd1234z", "1234", 4, 0), "abcd1234abcd1234z"));
- assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678", 4, "12345678", 8), "12345678abcdefgh12345678"));
- assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678z", 4, "zzzzzzzz", 8), "z"));
- assert(!strcmpnul(libsimple_memelemscan("efgh12345678abcdefgh12345678abcdz", 4, "12345678", 8), "z"));
- assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678z", 0, "12345678", 8),
+ assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678", "12345678", 8, 4), "12345678abcdefgh12345678"));
+ assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678z", "zzzzzzzz", 8, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("efgh12345678abcdefgh12345678abcdz", "12345678", 8, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("abcdefgh12345678abcdefgh12345678z", "12345678", 8, 0),
"abcdefgh12345678abcdefgh12345678z"));
- assert(!strcmpnul(libsimple_memelemscan("abc123abc123", 4, "123", 3), "123abc123"));
- assert(!strcmpnul(libsimple_memelemscan("abc123abc123z", 4, "zzz", 3), "z"));
- assert(!strcmpnul(libsimple_memelemscan("bc123abc123az", 4, "123", 3), "z"));
- assert(!strcmpnul(libsimple_memelemscan("abc123abc123z", 0, "123", 3), "abc123abc123z"));
+ assert(!strcmpnul(libsimple_memelemscan("abc123abc123", "123", 3, 4), "123abc123"));
+ assert(!strcmpnul(libsimple_memelemscan("abc123abc123z", "zzz", 3, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("bc123abc123az", "123", 3, 4), "z"));
+ assert(!strcmpnul(libsimple_memelemscan("abc123abc123z", "123", 3, 0), "abc123abc123z"));
- assert(!strcmpnul(libsimple_memelemscan("-a-aa--a", 4, "a-", 2), "a--a"));
- assert(!strcmpnul(libsimple_memelemscan("--a--aa----a", 4, "a--", 3), "a----a"));
- assert(!strcmpnul(libsimple_memelemscan("---a---aa------a", 4, "a---", 4), "a------a"));
- assert(!strcmpnul(libsimple_memelemscan("-------a-------aa--------------a", 4, "a-------", 8), "a--------------a"));
+ assert(!strcmpnul(libsimple_memelemscan("-a-aa--a", "a-", 2, 4), "a--a"));
+ assert(!strcmpnul(libsimple_memelemscan("--a--aa----a", "a--", 3, 4), "a----a"));
+ assert(!strcmpnul(libsimple_memelemscan("---a---aa------a", "a---", 4, 4), "a------a"));
+ assert(!strcmpnul(libsimple_memelemscan("-------a-------aa--------------a", "a-------", 8, 4), "a--------------a"));
return 0;
}
diff --git a/memelemscan_inv.c b/memelemscan_inv.c
index 7e7a0a4..37b479a 100644
--- a/memelemscan_inv.c
+++ b/memelemscan_inv.c
@@ -4,32 +4,32 @@
void *
-libsimple_memelemscan_inv(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memelemscan_inv(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
- return libsimple_memscan_inv(hay_, *(char *)sub_, hayn);
+ return libsimple_memscan_inv(hay_, *(char *)sub_, n);
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (; hayn-- && *hay == sub; hay++);
+ for (; n-- && *hay == sub; hay++);
return hay;
}
case 4:
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (; hayn-- && *hay == sub; hay++);
+ for (; n-- && *hay == sub; hay++);
return hay;
}
case 8:
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (; hayn-- && *hay == sub; hay++);
+ for (; n-- && *hay == sub; hay++);
return hay;
}
default:
@@ -37,8 +37,8 @@ libsimple_memelemscan_inv(const void *hay_, size_t hayn, const void *sub_, size_
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (; hayn--; hay += subn) {
- for (i = 0; i < subn; i++)
+ for (; n--; hay += width) {
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
return hay;
}
@@ -54,49 +54,49 @@ libsimple_memelemscan_inv(const void *hay_, size_t hayn, const void *sub_, size_
int
main(void)
{
- assert(!strcmpnul(libsimple_memelemscan_inv("xxoxx", 5, "x", 0), "xxoxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("xxXxx", 5, "x", 0), "xxXxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("XXoxx", 5, "x", 0), "XXoxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("zzzzz", 5, "z", 0), "zzzzz"));
- assert(!strcmpnul(libsimple_memelemscan_inv("zzzzx", 3, "z", 0), "zzzzx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("xxoxx", "x", 0, 5), "xxoxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("xxXxx", "x", 0, 5), "xxXxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("XXoxx", "x", 0, 5), "XXoxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("zzzzz", "z", 0, 5), "zzzzz"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("zzzzx", "z", 0, 3), "zzzzx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("xxoxx", 5, "x", 1), "oxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("xxXxx", 5, "x", 1), "Xxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("XXoxx", 5, "x", 1), "XXoxx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("zzzzz", 5, "z", 1), ""));
- assert(!strcmpnul(libsimple_memelemscan_inv("zzzzx", 3, "z", 1), "zx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("xxoxx", "x", 1, 5), "oxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("xxXxx", "x", 1, 5), "Xxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("XXoxx", "x", 1, 5), "XXoxx"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("zzzzz", "z", 1, 5), ""));
+ assert(!strcmpnul(libsimple_memelemscan_inv("zzzzx", "z", 1, 3), "zx"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-x-x-o-x-x", 5, "-x", 2), "-o-x-x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-x-x-X-x-x", 5, "-x", 2), "-X-x-x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-X-X-o-x-x", 5, "-x", 2), "-X-X-o-x-x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-z-z-z-z-z", 5, "-z", 2), ""));
- assert(!strcmpnul(libsimple_memelemscan_inv("-z-z-z-z-x", 3, "-z", 2), "-z-x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---z-z-z-x", 5, "--", 2), "-z-z-z-x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-x-x-o-x-x", "-x", 2, 5), "-o-x-x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-x-x-X-x-x", "-x", 2, 5), "-X-x-x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-X-X-o-x-x", "-x", 2, 5), "-X-X-o-x-x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-z-z-z-z-z", "-z", 2, 5), ""));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-z-z-z-z-x", "-z", 2, 3), "-z-x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---z-z-z-x", "--", 2, 5), "-z-z-z-x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("--x--x--o--x--x", 5, "--x", 3), "--o--x--x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("--x--x--X--x--x", 5, "--x", 3), "--X--x--x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("--X--X--o--x--x", 5, "--x", 3), "--X--X--o--x--x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("--z--z--z--z--z", 5, "--z", 3), ""));
- assert(!strcmpnul(libsimple_memelemscan_inv("--z--z--z--z--x", 3, "--z", 3), "--z--x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-----z--z--z--x", 5, "---", 3), "--z--z--z--x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("--x--x--o--x--x", "--x", 3, 5), "--o--x--x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("--x--x--X--x--x", "--x", 3, 5), "--X--x--x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("--X--X--o--x--x", "--x", 3, 5), "--X--X--o--x--x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("--z--z--z--z--z", "--z", 3, 5), ""));
+ assert(!strcmpnul(libsimple_memelemscan_inv("--z--z--z--z--x", "--z", 3, 3), "--z--x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-----z--z--z--x", "---", 3, 5), "--z--z--z--x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---x---x---o---x---x", 5, "---x", 4), "---o---x---x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---x---x---X---x---x", 5, "---x", 4), "---X---x---x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---X---X---o---x---x", 5, "---x", 4), "---X---X---o---x---x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---z---z---z---z---z", 5, "---z", 4), ""));
- assert(!strcmpnul(libsimple_memelemscan_inv("---z---z---z---z---x", 3, "---z", 4), "---z---x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------z---z---z---x", 5, "----", 4), "---z---z---z---x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---x---x---o---x---x", "---x", 4, 5), "---o---x---x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---x---x---X---x---x", "---x", 4, 5), "---X---x---x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---X---X---o---x---x", "---x", 4, 5), "---X---X---o---x---x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---z---z---z---z---z", "---z", 4, 5), ""));
+ assert(!strcmpnul(libsimple_memelemscan_inv("---z---z---z---z---x", "---z", 4, 3), "---z---x"));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------z---z---z---x", "----", 4, 5), "---z---z---z---x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------x-------x-------o-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------x-------x-------o-------x-------x", "-------x", 8, 5),
"-------o-------x-------x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------x-------x-------X-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------x-------x-------X-------x-------x", "-------x", 8, 5),
"-------X-------x-------x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------X-------X-------o-------x-------x", 5, "-------x", 8),
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------X-------X-------o-------x-------x", "-------x", 8, 5),
"-------X-------X-------o-------x-------x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------z-------z-------z-------z-------z", 5, "-------z", 8), ""));
- assert(!strcmpnul(libsimple_memelemscan_inv("-------z-------z-------z-------z-------x", 3, "-------z", 8),
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------z-------z-------z-------z-------z", "-------z", 8, 5), ""));
+ assert(!strcmpnul(libsimple_memelemscan_inv("-------z-------z-------z-------z-------x", "-------z", 8, 3),
"-------z-------x"));
- assert(!strcmpnul(libsimple_memelemscan_inv("---------------z-------z-------z-------x", 5, "--------", 8),
+ assert(!strcmpnul(libsimple_memelemscan_inv("---------------z-------z-------z-------x", "--------", 8, 5),
"-------z-------z-------z-------x"));
return 0;
diff --git a/mempsetelem.c b/mempsetelem.c
index 6759579..6a3bd4f 100644
--- a/mempsetelem.c
+++ b/mempsetelem.c
@@ -4,17 +4,17 @@
void *
-libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
+libsimple_mempsetelem(void *buf_, const void *item, size_t width, size_t n)
{
- switch (size) {
+ switch (width) {
case 0:
return buf_;
case 1:
- return &((char *)memset(buf_, *(char *)item, nitems))[nitems];
+ return &((char *)memset(buf_, *(char *)item, n))[n];
case 2:
{
uint16_t *buf = buf_, e = *(uint16_t *)item;
- uint16_t *end = &buf[nitems];
+ uint16_t *end = &buf[n];
for (; buf != end; buf++)
*buf = e;
return buf;
@@ -22,7 +22,7 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
case 4:
{
uint32_t *buf = buf_, e = *(uint32_t *)item;
- uint32_t *end = &buf[nitems];
+ uint32_t *end = &buf[n];
for (; buf != end; buf++)
*buf = e;
return buf;
@@ -30,7 +30,7 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
case 8:
{
uint64_t *buf = buf_, e = *(uint64_t *)item;
- uint64_t *end = &buf[nitems];
+ uint64_t *end = &buf[n];
for (; buf != end; buf++)
*buf = e;
return buf;
@@ -39,8 +39,8 @@ libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems)
{
char *buf = buf_;
size_t i;
- for (; nitems--; buf += size)
- for (i = 0; i < size; i++)
+ for (; n--; buf += width)
+ for (i = 0; i < width; i++)
buf[i] = ((const char *)item)[i];
return buf;
}
diff --git a/memrelem.c b/memrelem.c
index ca45136..5b9cf8f 100644
--- a/memrelem.c
+++ b/memrelem.c
@@ -4,16 +4,16 @@
void *
-libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memrelem(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
{
uint8_t *hay = (void *)hay_;
uint8_t sub = *(uint8_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay == sub)
return hay;
break;
@@ -22,7 +22,7 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay == sub)
return hay;
break;
@@ -31,7 +31,7 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay == sub)
return hay;
break;
@@ -40,7 +40,7 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay == sub)
return hay;
break;
@@ -50,9 +50,9 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (hay += hayn * subn; hayn--;) {
- hay -= subn;
- for (i = 0; i < subn; i++)
+ for (hay += n * width; n--;) {
+ hay -= width;
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
goto next;
return hay;
@@ -72,38 +72,38 @@ libsimple_memrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
int
main(void)
{
- assert(!strcmpnul(libsimple_memrelem("12345634", 8, "", 0), "12345634"));
- assert(!strcmpnul(libsimple_memrelem("12345634", 0, "", 0), "12345634"));
+ assert(!strcmpnul(libsimple_memrelem("12345634", "", 0, 8), "12345634"));
+ assert(!strcmpnul(libsimple_memrelem("12345634", "", 0, 0), "12345634"));
- assert(!strcmpnul(libsimple_memrelem("12345634", 8, "3", 1), "34"));
- assert(!libsimple_memrelem("12345634", 8, "x", 1));
- assert(!strcmpnul(libsimple_memrelem("13456342", 8, "3", 1), "342"));
- assert(!libsimple_memrelem("12345634", 0, "3", 1));
+ assert(!strcmpnul(libsimple_memrelem("12345634", "3", 1, 8), "34"));
+ assert(!libsimple_memrelem("12345634", "x", 1, 8));
+ assert(!strcmpnul(libsimple_memrelem("13456342", "3", 1, 8), "342"));
+ assert(!libsimple_memrelem("12345634", "3", 1, 0));
- assert(!strcmpnul(libsimple_memrelem("12345634", 4, "34", 2), "34"));
- assert(!libsimple_memrelem("12345634", 4, "xx", 2));
- assert(!libsimple_memrelem("13456342", 4, "34", 2));
- assert(!libsimple_memrelem("12345634", 0, "34", 2));
+ assert(!strcmpnul(libsimple_memrelem("12345634", "34", 2, 4), "34"));
+ assert(!libsimple_memrelem("12345634", "xx", 2, 4));
+ assert(!libsimple_memrelem("13456342", "34", 2, 4));
+ assert(!libsimple_memrelem("12345634", "34", 2, 0));
- assert(!strcmpnul(libsimple_memrelem("abcd1234abcd1234", 4, "1234", 4), "1234"));
- assert(!libsimple_memrelem("abcd1234abcd1234", 4, "zzzz", 4));
- assert(!libsimple_memrelem("cd1234abcd1234ab", 4, "1234", 4));
- assert(!libsimple_memrelem("abcd1234abcd1234", 0, "1234", 4));
+ assert(!strcmpnul(libsimple_memrelem("abcd1234abcd1234", "1234", 4, 4), "1234"));
+ assert(!libsimple_memrelem("abcd1234abcd1234", "zzzz", 4, 4));
+ assert(!libsimple_memrelem("cd1234abcd1234ab", "1234", 4, 4));
+ assert(!libsimple_memrelem("abcd1234abcd1234", "1234", 4, 0));
- assert(!strcmpnul(libsimple_memrelem("abcdefgh12345678abcdefgh12345678", 4, "12345678", 8), "12345678"));
- assert(!libsimple_memrelem("abcdefgh12345678abcdefgh12345678", 4, "zzzzzzzz", 8));
- assert(!libsimple_memrelem("efgh12345678abcdefgh12345678abcd", 4, "12345678", 8));
- assert(!libsimple_memrelem("abcdefgh12345678abcdefgh12345678", 0, "12345678", 8));
+ assert(!strcmpnul(libsimple_memrelem("abcdefgh12345678abcdefgh12345678", "12345678", 8, 4), "12345678"));
+ assert(!libsimple_memrelem("abcdefgh12345678abcdefgh12345678", "zzzzzzzz", 8, 4));
+ assert(!libsimple_memrelem("efgh12345678abcdefgh12345678abcd", "12345678", 8, 4));
+ assert(!libsimple_memrelem("abcdefgh12345678abcdefgh12345678", "12345678", 8, 0));
- assert(!strcmpnul(libsimple_memrelem("abc123abc123", 4, "123", 3), "123"));
- assert(!libsimple_memrelem("abc123abc123", 4, "zzz", 3));
- assert(!libsimple_memrelem("bc123abc123a", 4, "123", 3));
- assert(!libsimple_memrelem("abc123abc123", 0, "123", 3));
+ assert(!strcmpnul(libsimple_memrelem("abc123abc123", "123", 3, 4), "123"));
+ assert(!libsimple_memrelem("abc123abc123", "zzz", 3, 4));
+ assert(!libsimple_memrelem("bc123abc123a", "123", 3, 4));
+ assert(!libsimple_memrelem("abc123abc123", "123", 3, 0));
- assert(!strcmpnul(libsimple_memrelem("-a-aa--a", 4, "a-", 2), "a--a"));
- assert(!strcmpnul(libsimple_memrelem("--a--aa----a", 4, "a--", 3), "a----a"));
- assert(!strcmpnul(libsimple_memrelem("---a---aa------a", 4, "a---", 4), "a------a"));
- assert(!strcmpnul(libsimple_memrelem("-------a-------aa--------------a", 4, "a-------", 8), "a--------------a"));
+ assert(!strcmpnul(libsimple_memrelem("-a-aa--a", "a-", 2, 4), "a--a"));
+ assert(!strcmpnul(libsimple_memrelem("--a--aa----a", "a--", 3, 4), "a----a"));
+ assert(!strcmpnul(libsimple_memrelem("---a---aa------a", "a---", 4, 4), "a------a"));
+ assert(!strcmpnul(libsimple_memrelem("-------a-------aa--------------a", "a-------", 8, 4), "a--------------a"));
return 0;
}
diff --git a/memrelem_inv.c b/memrelem_inv.c
index 6d98a55..d90f358 100644
--- a/memrelem_inv.c
+++ b/memrelem_inv.c
@@ -4,16 +4,16 @@
void *
-libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_memrelem_inv(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return NULL;
case 1:
{
uint8_t *hay = (void *)hay_;
uint8_t sub = *(uint8_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay != sub)
return hay;
break;
@@ -22,7 +22,7 @@ libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t s
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay != sub)
return hay;
break;
@@ -31,7 +31,7 @@ libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t s
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay != sub)
return hay;
break;
@@ -40,7 +40,7 @@ libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t s
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (hay += hayn; hayn--;)
+ for (hay += n; n--;)
if (*--hay != sub)
return hay;
break;
@@ -50,9 +50,9 @@ libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t s
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (hay += hayn * subn; hayn--;) {
- hay -= subn;
- for (i = 0; i < subn; i++)
+ for (hay += n * width; n--;) {
+ hay -= width;
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
return hay;
}
@@ -70,65 +70,65 @@ libsimple_memrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t s
int
main(void)
{
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "b", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "B", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", 8, "b", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", 8, "B", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "a", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbbb\0\0", 8, "\0", 0), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("--------", 8, "-", 0), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "b", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "B", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", "b", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", "B", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "a", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbbb\0\0", "\0", 0, 8), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("--------", "-", 0, 8), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "b", 1), "abb"));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "B", 1), "b"));
- assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", 8, "b", 1), "B"));
- assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", 8, "B", 1), "ABB"));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", 8, "a", 1), "b"));
- assert(!strcmpnul(libsimple_memrelem_inv("aabbbb\0\0", 8, "\0", 1), "b"));
- assert(!strcmpnul(libsimple_memrelem_inv("--------", 8, "-", 1), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "b", 1, 8), "abb"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "B", 1, 8), "b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", "b", 1, 8), "B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("AABBAABB", "B", 1, 8), "ABB"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbaabb", "a", 1, 8), "b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aabbbb\0\0", "\0", 1, 8), "b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--------", "-", 1, 8), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", 8, "-b", 2), "-a-b-b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", 8, "-B", 2), "-b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-A-A-B-B-A-A-B-B", 8, "-b", 2), "-B"));
- assert(!strcmpnul(libsimple_memrelem_inv("-A-A-B-B-A-A-B-B", 8, "-B", 2), "-A-B-B"));
- assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", 8, "-a", 2), "-b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-b-b\0\0\0\0", 8, "\0\0", 2), "-b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-x-x-x-x-x-x-x-x", 8, "-x", 2), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", "-b", 2, 8), "-a-b-b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", "-B", 2, 8), "-b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-A-A-B-B-A-A-B-B", "-b", 2, 8), "-B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-A-A-B-B-A-A-B-B", "-B", 2, 8), "-A-B-B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-a-a-b-b", "-a", 2, 8), "-b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-a-a-b-b-b-b\0\0\0\0", "\0\0", 2, 8), "-b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-x-x-x-x-x-x-x-x", "-x", 2, 8), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", 8, "--b", 3), "--a--b--b"));
- assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", 8, "--B", 3), "--b"));
- assert(!strcmpnul(libsimple_memrelem_inv("--A--A--B--B--A--A--B--B", 8, "--b", 3), "--B"));
- assert(!strcmpnul(libsimple_memrelem_inv("--A--A--B--B--A--A--B--B", 8, "--B", 3), "--A--B--B"));
- assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", 8, "--a", 3), "--b"));
- assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--b--b\0\0\0\0\0\0", 8, "\0\0\0", 3), "--b"));
- assert(!strcmpnul(libsimple_memrelem_inv("--x--x--x--x--x--x--x--x", 8, "--x", 3), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", "--b", 3, 8), "--a--b--b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", "--B", 3, 8), "--b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--A--A--B--B--A--A--B--B", "--b", 3, 8), "--B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--A--A--B--B--A--A--B--B", "--B", 3, 8), "--A--B--B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--a--a--b--b", "--a", 3, 8), "--b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--a--a--b--b--b--b\0\0\0\0\0\0", "\0\0\0", 3, 8), "--b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("--x--x--x--x--x--x--x--x", "--x", 3, 8), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", 8, "---b", 4), "---a---b---b"));
- assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", 8, "---B", 4), "---b"));
- assert(!strcmpnul(libsimple_memrelem_inv("---A---A---B---B---A---A---B---B", 8, "---b", 4), "---B"));
- assert(!strcmpnul(libsimple_memrelem_inv("---A---A---B---B---A---A---B---B", 8, "---B", 4), "---A---B---B"));
- assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", 8, "---a", 4), "---b"));
- assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---b---b\0\0\0\0\0\0\0\0", 8, "\0\0\0\0", 4), "---b"));
- assert(!strcmpnul(libsimple_memrelem_inv("---x---x---x---x---x---x---x---x", 8, "---x", 4), NULL));
+ assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", "---b", 4, 8), "---a---b---b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", "---B", 4, 8), "---b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---A---A---B---B---A---A---B---B", "---b", 4, 8), "---B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---A---A---B---B---A---A---B---B", "---B", 4, 8), "---A---B---B"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---a---a---b---b", "---a", 4, 8), "---b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---a---a---b---b---b---b\0\0\0\0\0\0\0\0", "\0\0\0\0", 4, 8), "---b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("---x---x---x---x---x---x---x---x", "---x", 4, 8), NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8, "-------b", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", "-------b", 8, 8),
"-------a-------b-------b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8, "-------B", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", "-------B", 8, 8),
"-------b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", 8, "-------b", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", "-------b", 8, 8),
"-------B"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", 8, "-------B", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", "-------B", 8, 8),
"-------A-------B-------B"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8, "-------a", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", "-------a", 8, 8),
"-------b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------b-------b\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 8,
- "\0\0\0\0\0\0\0\0", 8), "-------b"));
- assert(!strcmpnul(libsimple_memrelem_inv("-------x-------x-------x-------x-------x-------x-------x-------x", 8, "-------x", 8),
+ assert(!strcmpnul(libsimple_memrelem_inv("-------a-------a-------b-------b-------b-------b\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+ "\0\0\0\0\0\0\0\0", 8, 8), "-------b"));
+ assert(!strcmpnul(libsimple_memrelem_inv("-------x-------x-------x-------x-------x-------x-------x-------x", "-------x", 8, 8),
NULL));
- assert(!strcmpnul(libsimple_memrelem_inv("aaaa-aaa", 4, "aa", 2), "-aaa"));
- assert(!strcmpnul(libsimple_memrelem_inv("aaaaaa-aaaaa", 4, "aaa", 3), "-aaaaa"));
- assert(!strcmpnul(libsimple_memrelem_inv("aaaaaaaa-aaaaaaa", 4, "aaaa", 4), "-aaaaaaa"));
- assert(!strcmpnul(libsimple_memrelem_inv("aaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaa", 4, "aaaaaaaa", 8), "-aaaaaaaaaaaaaaa"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aaaa-aaa", "aa", 2, 4), "-aaa"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aaaaaa-aaaaa", "aaa", 3, 4), "-aaaaa"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aaaaaaaa-aaaaaaa", "aaaa", 4, 4), "-aaaaaaa"));
+ assert(!strcmpnul(libsimple_memrelem_inv("aaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaa", "aaaaaaaa", 8, 4), "-aaaaaaaaaaaaaaa"));
return 0;
}
diff --git a/memreplaceelem.c b/memreplaceelem.c
index 44f94a5..9a56c98 100644
--- a/memreplaceelem.c
+++ b/memreplaceelem.c
@@ -4,7 +4,7 @@
void *
-libsimple_memreplaceelem(void *restrict s_, const void *old_, const void *new_, size_t n, size_t width)
+libsimple_memreplaceelem(void *restrict s_, const void *old_, const void *new_, size_t width, size_t n)
{
switch (width) {
case 0:
@@ -80,64 +80,64 @@ main(void)
char buf[1024];
stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
- assert(libsimple_memreplaceelem(buf, "o", "x", 46, 0) == &buf[0]);
+ assert(libsimple_memreplaceelem(buf, "o", "x", 0, 46) == &buf[0]);
assert(!memcmp(buf, "hello world\0goodbye world", 26));
stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
- assert(libsimple_memreplaceelem(buf, "o", "x", 12, 0) == &buf[0]);
+ assert(libsimple_memreplaceelem(buf, "o", "x", 0, 12) == &buf[0]);
assert(!memcmp(buf, "hello world\0goodbye world", 26));
stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
- assert(libsimple_memreplaceelem(buf, "o", "x", 46, 1) == &buf[46]);
+ assert(libsimple_memreplaceelem(buf, "o", "x", 1, 46) == &buf[46]);
assert(!memcmp(buf, "hellx wxrld\0gxxdbye wxrld", 26));
stpcpy(mempcpy(buf, "hello world", 12), "goodbye world");
- assert(libsimple_memreplaceelem(buf, "o", "x", 12, 1) == &buf[12]);
+ assert(libsimple_memreplaceelem(buf, "o", "x", 1, 12) == &buf[12]);
assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26));
stpcpy(mempcpy(buf, "-h-e-l-l-o- -w-o-r-l-d\0", 12 * 2), "-g-o-o-d-b-y-e- -w-o-r-l-d");
- assert(libsimple_memreplaceelem(buf, "-o", "=x", 46, 2) == &buf[46 * 2]);
+ assert(libsimple_memreplaceelem(buf, "-o", "=x", 2, 46) == &buf[46 * 2]);
assert(!memcmp(buf, "-h-e-l-l=x- -w=x-r-l-d\0\0-g=x=x-d-b-y-e- -w=x-r-l-d", 25 * 2 + 1));
stpcpy(mempcpy(buf, "-h-e-l-l-o- -w-o-r-l-d\0", 12 * 2), "-g-o-o-d-b-y-e- -w-o-r-l-d");
- assert(libsimple_memreplaceelem(buf, "-o", "=x", 12, 2) == &buf[12 * 2]);
+ assert(libsimple_memreplaceelem(buf, "-o", "=x", 2, 12) == &buf[12 * 2]);
assert(!memcmp(buf, "-h-e-l-l=x- -w=x-r-l-d\0\0-g-o-o-d-b-y-e- -w-o-r-l-d", 25 * 2 + 1));
stpcpy(mempcpy(buf, "-h-e-l-l-o- -w-o-r-l-d\0", 12 * 2), "-g-o-o-d-b-y-e- -w-o-r-l-d");
- assert(libsimple_memreplaceelem(buf, "o-", "x=", 12, 2) == &buf[12 * 2]);
+ assert(libsimple_memreplaceelem(buf, "o-", "x=", 2, 12) == &buf[12 * 2]);
assert(!memcmp(buf, "-h-e-l-l-o- -w-o-r-l-d\0\0-g-o-o-d-b-y-e- -w-o-r-l-d", 25 * 2 + 1));
stpcpy(mempcpy(buf, "--h--e--l--l--o-- --w--o--r--l--d\0\0", 12 * 3), "--g--o--o--d--b--y--e-- --w--o--r--l--d");
- assert(libsimple_memreplaceelem(buf, "--o", "==x", 46, 3) == &buf[46 * 3]);
+ assert(libsimple_memreplaceelem(buf, "--o", "==x", 3, 46) == &buf[46 * 3]);
assert(!memcmp(buf, "--h--e--l--l==x-- --w==x--r--l--d\0\0\0--g==x==x--d--b--y--e-- --w==x--r--l--d", 25 * 3 + 1));
stpcpy(mempcpy(buf, "--h--e--l--l--o-- --w--o--r--l--d\0\0", 12 * 3), "--g--o--o--d--b--y--e-- --w--o--r--l--d");
- assert(libsimple_memreplaceelem(buf, "--o", "==x", 12, 3) == &buf[12 * 3]);
+ assert(libsimple_memreplaceelem(buf, "--o", "==x", 3, 12) == &buf[12 * 3]);
assert(!memcmp(buf, "--h--e--l--l==x-- --w==x--r--l--d\0\0\0--g--o--o--d--b--y--e-- --w--o--r--l--d", 25 * 3 + 1));
stpcpy(mempcpy(buf, "--h--e--l--l--o-- --w--o--r--l--d\0\0", 12 * 3), "--g--o--o--d--b--y--e-- --w--o--r--l--d");
- assert(libsimple_memreplaceelem(buf, "o--", "x==", 12, 3) == &buf[12 * 3]);
+ assert(libsimple_memreplaceelem(buf, "o--", "x==", 3, 12) == &buf[12 * 3]);
assert(!memcmp(buf, "--h--e--l--l--o-- --w--o--r--l--d\0\0\0--g--o--o--d--b--y--e-- --w--o--r--l--d", 25 * 3 + 1));
stpcpy(mempcpy(buf, "---h---e---l---l---o--- ---w---o---r---l---d\0\0\0", 12 * 4),
"---g---o---o---d---b---y---e--- ---w---o---r---l---d");
- assert(libsimple_memreplaceelem(buf, "---o", "===x", 46, 4) == &buf[46 * 4]);
+ assert(libsimple_memreplaceelem(buf, "---o", "===x", 4, 46) == &buf[46 * 4]);
assert(!memcmp(buf, "---h---e---l---l===x--- ---w===x---r---l---d\0\0\0\0"
"---g===x===x---d---b---y---e--- ---w===x---r---l---d", 25 * 4 + 1));
stpcpy(mempcpy(buf, "---h---e---l---l---o--- ---w---o---r---l---d\0\0\0", 12 * 4),
"---g---o---o---d---b---y---e--- ---w---o---r---l---d");
- assert(libsimple_memreplaceelem(buf, "---o", "===x", 12, 4) == &buf[12 * 4]);
+ assert(libsimple_memreplaceelem(buf, "---o", "===x", 4, 12) == &buf[12 * 4]);
assert(!memcmp(buf, "---h---e---l---l===x--- ---w===x---r---l---d\0\0\0\0"
"---g---o---o---d---b---y---e--- ---w---o---r---l---d", 25 * 4 + 1));
stpcpy(mempcpy(buf, "---h---e---l---l---o--- ---w---o---r---l---d\0\0\0", 12 * 4),
"---g---o---o---d---b---y---e--- ---w---o---r---l---d");
- assert(libsimple_memreplaceelem(buf, "o---", "x===", 12, 4) == &buf[12 * 4]);
+ assert(libsimple_memreplaceelem(buf, "o---", "x===", 4, 12) == &buf[12 * 4]);
assert(!memcmp(buf, "---h---e---l---l---o--- ---w---o---r---l---d\0\0\0\0"
"---g---o---o---d---b---y---e--- ---w---o---r---l---d", 25 * 4 + 1));
@@ -145,7 +145,7 @@ main(void)
stpcpy(mempcpy(buf, "-------h-------e-------l-------l-------o------- -------w-------o-------r-------l-------d\0\0\0\0\0\0\0",
12 * 8),
"-------g-------o-------o-------d-------b-------y-------e------- -------w-------o-------r-------l-------d");
- assert(libsimple_memreplaceelem(buf, "-------o", "=======x", 46, 8) == &buf[46 * 8]);
+ assert(libsimple_memreplaceelem(buf, "-------o", "=======x", 8, 46) == &buf[46 * 8]);
assert(!memcmp(buf, "-------h-------e-------l-------l=======x------- -------w=======x-------r-------l-------d\0\0\0\0\0\0\0\0"
"-------g=======x=======x-------d-------b-------y-------e------- "
"-------w=======x-------r-------l-------d", 25 * 8 + 1));
@@ -153,7 +153,7 @@ main(void)
stpcpy(mempcpy(buf, "-------h-------e-------l-------l-------o------- -------w-------o-------r-------l-------d\0\0\0\0\0\0\0",
12 * 8),
"-------g-------o-------o-------d-------b-------y-------e------- -------w-------o-------r-------l-------d");
- assert(libsimple_memreplaceelem(buf, "-------o", "=======x", 12, 8) == &buf[12 * 8]);
+ assert(libsimple_memreplaceelem(buf, "-------o", "=======x", 8, 12) == &buf[12 * 8]);
assert(!memcmp(buf, "-------h-------e-------l-------l=======x------- -------w=======x-------r-------l-------d\0\0\0\0\0\0\0\0"
"-------g-------o-------o-------d-------b-------y-------e------- "
"-------w-------o-------r-------l-------d", 25 * 8 + 1));
@@ -161,7 +161,7 @@ main(void)
stpcpy(mempcpy(buf, "-------h-------e-------l-------l-------o------- -------w-------o-------r-------l-------d\0\0\0\0\0\0\0",
12 * 8),
"-------g-------o-------o-------d-------b-------y-------e------- -------w-------o-------r-------l-------d");
- assert(libsimple_memreplaceelem(buf, "o-------", "x=======", 12, 8) == &buf[12 * 8]);
+ assert(libsimple_memreplaceelem(buf, "o-------", "x=======", 8, 12) == &buf[12 * 8]);
assert(!memcmp(buf, "-------h-------e-------l-------l-------o------- -------w-------o-------r-------l-------d\0\0\0\0\0\0\0\0"
"-------g-------o-------o-------d-------b-------y-------e------- "
"-------w-------o-------r-------l-------d", 25 * 8 + 1));
diff --git a/rawmemelem.c b/rawmemelem.c
index d2d743a..fa67a51 100644
--- a/rawmemelem.c
+++ b/rawmemelem.c
@@ -4,9 +4,9 @@
void *
-libsimple_rawmemelem(const void *hay_, const void *sub_, size_t subn)
+libsimple_rawmemelem(const void *hay_, const void *sub_, size_t width)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
@@ -37,8 +37,8 @@ libsimple_rawmemelem(const void *hay_, const void *sub_, size_t subn)
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (;; hay += subn) {
- for (i = 0; i < subn; i++)
+ for (;; hay += width) {
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
goto next;
return hay;
diff --git a/rawmemelem_inv.c b/rawmemelem_inv.c
index 0946a48..7046d3c 100644
--- a/rawmemelem_inv.c
+++ b/rawmemelem_inv.c
@@ -4,9 +4,9 @@
void *
-libsimple_rawmemelem_inv(const void *hay_, const void *sub_, size_t subn)
+libsimple_rawmemelem_inv(const void *hay_, const void *sub_, size_t width)
{
- switch (subn) {
+ switch (width) {
case 0:
abort();
case 1:
@@ -37,8 +37,8 @@ libsimple_rawmemelem_inv(const void *hay_, const void *sub_, size_t subn)
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (;; hay += subn)
- for (i = 0; i < subn; i++)
+ for (;; hay += width)
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
return hay;
}
diff --git a/rawmemelemcpy.c b/rawmemelemcpy.c
index 2f0f9f0..ef6b21c 100644
--- a/rawmemelemcpy.c
+++ b/rawmemelemcpy.c
@@ -36,27 +36,27 @@ rawmemelemcpy64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem)
static inline char *
-rawmemelemcpyx(char *restrict d, const char *restrict s, const char *restrict elem, size_t size)
+rawmemelemcpyx(char *restrict d, const char *restrict s, const char *restrict elem, size_t width)
{
size_t i;
- for (;; s += size) {
- for (i = 0; i < size; i++)
+ for (;; s += width) {
+ for (i = 0; i < width; i++)
d[i] = s[i];
- for (i = 0; i < size; i++)
+ for (i = 0; i < width; i++)
if (d[i] != elem[i])
goto next;
- d += size;
+ d += width;
return d;
next:
- d += size;
+ d += width;
}
}
void *
-libsimple_rawmemelemcpy(void *restrict d, const void *restrict s, const void *restrict elem, size_t size) /* TODO man */
+libsimple_rawmemelemcpy(void *restrict d, const void *restrict s, const void *restrict elem, size_t width) /* TODO man */
{
- switch (size) {
+ switch (width) {
case 0:
return d;
case 1:
@@ -68,7 +68,7 @@ libsimple_rawmemelemcpy(void *restrict d, const void *restrict s, const void *re
case 8:
return rawmemelemcpy64(d, s, *(const uint64_t *)elem);
default:
- return rawmemelemcpyx(d, s, elem, size);
+ return rawmemelemcpyx(d, s, elem, width);
}
}
diff --git a/rawmemelemmove.c b/rawmemelemmove.c
index c663219..220ec25 100644
--- a/rawmemelemmove.c
+++ b/rawmemelemmove.c
@@ -45,31 +45,31 @@ rawmemelemmove64(uint64_t *restrict d, const uint64_t *restrict s, uint64_t elem
static char *
-rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t size)
+rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict elem, size_t width)
{
char *p;
size_t i, n;
if (d <= s) {
- for (;; s += size) {
- for (i = 0; i < size; i++)
+ for (;; s += width) {
+ for (i = 0; i < width; i++)
d[i] = s[i];
- for (i = 0; i < size; i++)
+ for (i = 0; i < width; i++)
if (d[i] != elem[i])
goto next_forwards;
- d += size;
+ d += width;
return d;
next_forwards:
- d += size;
+ d += width;
}
} else {
for (p = *(char **)(void *)&s;;) {
- for (i = 0; i < size; i++)
+ for (i = 0; i < width; i++)
if (p[i] != elem[i])
goto next_backwards;
- p += size;
+ p += width;
break;
next_backwards:
- p += size;
+ p += width;
}
n = (size_t)(p - s);
p = &d[n];
@@ -83,9 +83,9 @@ rawmemelemmovex(char *restrict d, const char *restrict s, const char *restrict e
void *
-libsimple_rawmemelemmove(void *d, const void *s, const void *restrict elem, size_t size) /* TODO man */
+libsimple_rawmemelemmove(void *d, const void *s, const void *restrict elem, size_t width) /* TODO man */
{
- switch (size) {
+ switch (width) {
case 0:
return d;
case 1:
@@ -97,7 +97,7 @@ libsimple_rawmemelemmove(void *d, const void *s, const void *restrict elem, size
case 8:
return rawmemelemmove64(d, s, *(const uint64_t *)elem);
default:
- return rawmemelemmovex(d, s, elem, size);
+ return rawmemelemmovex(d, s, elem, width);
}
}
diff --git a/rawmemrelem.c b/rawmemrelem.c
index 078aa05..d8507b3 100644
--- a/rawmemrelem.c
+++ b/rawmemrelem.c
@@ -4,37 +4,37 @@
void *
-libsimple_rawmemrelem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_rawmemrelem(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
return (void *)hay_;
case 1:
{
uint8_t *hay = (void *)hay_;
uint8_t sub = *(uint8_t *)sub_;
- for (hay += hayn; *--hay != sub;);
+ for (hay += n; *--hay != sub;);
return hay;
}
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (hay += hayn; *--hay != sub;);
+ for (hay += n; *--hay != sub;);
return hay;
}
case 4:
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (hay += hayn; *--hay != sub;);
+ for (hay += n; *--hay != sub;);
return hay;
}
case 8:
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (hay += hayn; *--hay != sub;);
+ for (hay += n; *--hay != sub;);
return hay;
}
default:
@@ -42,9 +42,9 @@ libsimple_rawmemrelem(const void *hay_, size_t hayn, const void *sub_, size_t su
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (hay += hayn * subn;;) {
- hay -= subn;
- for (i = 0; i < subn; i++)
+ for (hay += n * width;;) {
+ hay -= width;
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
goto next;
return hay;
@@ -61,18 +61,18 @@ libsimple_rawmemrelem(const void *hay_, size_t hayn, const void *sub_, size_t su
int
main(void)
{
- assert(!strcmpnul(libsimple_rawmemrelem("12345634", 8, "", 0), "12345634"));
- assert(!strcmpnul(libsimple_rawmemrelem("12345634", 8, "3", 1), "34"));
- assert(!strcmpnul(libsimple_rawmemrelem("13456342", 8, "3", 1), "342"));
- assert(!strcmpnul(libsimple_rawmemrelem("12345634", 4, "34", 2), "34"));
- assert(!strcmpnul(libsimple_rawmemrelem("abcd1234abcd1234", 4, "1234", 4), "1234"));
- assert(!strcmpnul(libsimple_rawmemrelem("abcdefgh12345678abcdefgh12345678", 4, "12345678", 8), "12345678"));
- assert(!strcmpnul(libsimple_rawmemrelem("abc123abc123", 4, "123", 3), "123"));
+ assert(!strcmpnul(libsimple_rawmemrelem("12345634", "", 0, 8), "12345634"));
+ assert(!strcmpnul(libsimple_rawmemrelem("12345634", "3", 1, 8), "34"));
+ assert(!strcmpnul(libsimple_rawmemrelem("13456342", "3", 1, 8), "342"));
+ assert(!strcmpnul(libsimple_rawmemrelem("12345634", "34", 2, 4), "34"));
+ assert(!strcmpnul(libsimple_rawmemrelem("abcd1234abcd1234", "1234", 4, 4), "1234"));
+ assert(!strcmpnul(libsimple_rawmemrelem("abcdefgh12345678abcdefgh12345678", "12345678", 8, 4), "12345678"));
+ assert(!strcmpnul(libsimple_rawmemrelem("abc123abc123", "123", 3, 4), "123"));
- assert(!strcmpnul(libsimple_rawmemrelem("-aa--a-a", 4, "a-", 2), "a--a-a"));
- assert(!strcmpnul(libsimple_rawmemrelem("--aa----a--a", 4, "a--", 3), "a----a--a"));
- assert(!strcmpnul(libsimple_rawmemrelem("---aa------a---a", 4, "a---", 4), "a------a---a"));
- assert(!strcmpnul(libsimple_rawmemrelem("-------aa--------------a-------a", 4, "a-------", 8), "a--------------a-------a"));
+ assert(!strcmpnul(libsimple_rawmemrelem("-aa--a-a", "a-", 2, 4), "a--a-a"));
+ assert(!strcmpnul(libsimple_rawmemrelem("--aa----a--a", "a--", 3, 4), "a----a--a"));
+ assert(!strcmpnul(libsimple_rawmemrelem("---aa------a---a", "a---", 4, 4), "a------a---a"));
+ assert(!strcmpnul(libsimple_rawmemrelem("-------aa--------------a-------a", "a-------", 8, 4), "a--------------a-------a"));
return 0;
}
diff --git a/rawmemrelem_inv.c b/rawmemrelem_inv.c
index 6c16697..74a3cfc 100644
--- a/rawmemrelem_inv.c
+++ b/rawmemrelem_inv.c
@@ -4,37 +4,37 @@
void *
-libsimple_rawmemrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_t subn)
+libsimple_rawmemrelem_inv(const void *hay_, const void *sub_, size_t width, size_t n)
{
- switch (subn) {
+ switch (width) {
case 0:
abort();
case 1:
{
uint8_t *hay = (void *)hay_;
uint8_t sub = *(uint8_t *)sub_;
- for (hay += hayn; *--hay == sub;);
+ for (hay += n; *--hay == sub;);
return hay;
}
case 2:
{
uint16_t *hay = (void *)hay_;
uint16_t sub = *(uint16_t *)sub_;
- for (hay += hayn; *--hay == sub;);
+ for (hay += n; *--hay == sub;);
return hay;
}
case 4:
{
uint32_t *hay = (void *)hay_;
uint32_t sub = *(uint32_t *)sub_;
- for (hay += hayn; *--hay == sub;);
+ for (hay += n; *--hay == sub;);
return hay;
}
case 8:
{
uint64_t *hay = (void *)hay_;
uint64_t sub = *(uint64_t *)sub_;
- for (hay += hayn; *--hay == sub;);
+ for (hay += n; *--hay == sub;);
return hay;
}
default:
@@ -42,9 +42,9 @@ libsimple_rawmemrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_
char *hay = (void *)hay_;
const char *sub = sub_;
size_t i;
- for (hay += hayn * subn;;) {
- hay -= subn;
- for (i = 0; i < subn; i++)
+ for (hay += n * width;;) {
+ hay -= width;
+ for (i = 0; i < width; i++)
if (hay[i] != sub[i])
return hay;
}
@@ -59,51 +59,51 @@ libsimple_rawmemrelem_inv(const void *hay_, size_t hayn, const void *sub_, size_
int
main(void)
{
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", 8, "b", 1), "abb"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", 8, "B", 1), "b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("AABBAABB", 8, "b", 1), "B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("AABBAABB", 8, "B", 1), "ABB"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", 8, "a", 1), "b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbbb\0\0", 8, "\0", 1), "b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", "b", 1, 8), "abb"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", "B", 1, 8), "b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("AABBAABB", "b", 1, 8), "B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("AABBAABB", "B", 1, 8), "ABB"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbaabb", "a", 1, 8), "b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aabbbb\0\0", "\0", 1, 8), "b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", 8, "-b", 2), "-a-b-b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", 8, "-B", 2), "-b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-A-A-B-B-A-A-B-B", 8, "-b", 2), "-B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-A-A-B-B-A-A-B-B", 8, "-B", 2), "-A-B-B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", 8, "-a", 2), "-b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-b-b\0\0\0\0", 8, "\0\0", 2), "-b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", "-b", 2, 8), "-a-b-b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", "-B", 2, 8), "-b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-A-A-B-B-A-A-B-B", "-b", 2, 8), "-B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-A-A-B-B-A-A-B-B", "-B", 2, 8), "-A-B-B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-a-a-b-b", "-a", 2, 8), "-b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-a-a-b-b-b-b\0\0\0\0", "\0\0", 2, 8), "-b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", 8, "--b", 3), "--a--b--b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", 8, "--B", 3), "--b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--A--A--B--B--A--A--B--B", 8, "--b", 3), "--B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--A--A--B--B--A--A--B--B", 8, "--B", 3), "--A--B--B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", 8, "--a", 3), "--b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--b--b\0\0\0\0\0\0", 8, "\0\0\0", 3), "--b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", "--b", 3, 8), "--a--b--b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", "--B", 3, 8), "--b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--A--A--B--B--A--A--B--B", "--b", 3, 8), "--B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--A--A--B--B--A--A--B--B", "--B", 3, 8), "--A--B--B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--a--a--b--b", "--a", 3, 8), "--b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("--a--a--b--b--b--b\0\0\0\0\0\0", "\0\0\0", 3, 8), "--b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", 8, "---b", 4), "---a---b---b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", 8, "---B", 4), "---b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---A---A---B---B---A---A---B---B", 8, "---b", 4), "---B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---A---A---B---B---A---A---B---B", 8, "---B", 4), "---A---B---B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", 8, "---a", 4), "---b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---b---b\0\0\0\0\0\0\0\0", 8, "\0\0\0\0", 4), "---b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", "---b", 4, 8), "---a---b---b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", "---B", 4, 8), "---b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---A---A---B---B---A---A---B---B", "---b", 4, 8), "---B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---A---A---B---B---A---A---B---B", "---B", 4, 8), "---A---B---B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---a---a---b---b", "---a", 4, 8), "---b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("---a---a---b---b---b---b\0\0\0\0\0\0\0\0", "\0\0\0\0", 4, 8), "---b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8,
- "-------b", 8), "-------a-------b-------b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8,
- "-------B", 8), "-------b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", 8,
- "-------b", 8), "-------B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B", 8,
- "-------B", 8), "-------A-------B-------B"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b", 8,
- "-------a", 8), "-------b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b",
+ "-------b", 8, 8), "-------a-------b-------b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b",
+ "-------B", 8, 8), "-------b"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B",
+ "-------b", 8, 8), "-------B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-------A-------A-------B-------B-------A-------A-------B-------B",
+ "-------B", 8, 8), "-------A-------B-------B"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------a-------a-------b-------b",
+ "-------a", 8, 8), "-------b"));
assert(!strcmpnul(libsimple_rawmemrelem_inv("-------a-------a-------b-------b-------b-------b"
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 8, "\0\0\0\0\0\0\0\0", 8), "-------b"));
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", "\0\0\0\0\0\0\0\0", 8, 8), "-------b"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaa-aaa", 4, "aa", 2), "-aaa"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaa-aaaaa", 4, "aaa", 3), "-aaaaa"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaaaa-aaaaaaa", 4, "aaaa", 4), "-aaaaaaa"));
- assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaa", 4, "aaaaaaaa", 8), "-aaaaaaaaaaaaaaa"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaa-aaa", "aa", 2, 4), "-aaa"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaa-aaaaa", "aaa", 3, 4), "-aaaaa"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaaaa-aaaaaaa", "aaaa", 4, 4), "-aaaaaaa"));
+ assert(!strcmpnul(libsimple_rawmemrelem_inv("aaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaa", "aaaaaaaa", 8, 4), "-aaaaaaaaaaaaaaa"));
return 0;
}