aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--libsimple/mem.h22
-rw-r--r--man/libsimple_memends.32
-rw-r--r--man/libsimple_memeq.32
-rw-r--r--man/libsimple_memmem.32
-rw-r--r--man/libsimple_memrcasechr.32
-rw-r--r--man/libsimple_memrchr.32
-rw-r--r--man/libsimple_memrmem.32
-rw-r--r--man/libsimple_memstarts.32
-rw-r--r--man/libsimple_rawmemcasechr.32
-rw-r--r--man/libsimple_rawmemchr.32
-rw-r--r--man/libsimple_rawmemrcasechr.383
-rw-r--r--man/libsimple_rawmemrchr.33
-rw-r--r--rawmemrcasechr.c33
-rw-r--r--rawmemrchr.c10
15 files changed, 158 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index a3a7b31..3b2f653 100644
--- a/Makefile
+++ b/Makefile
@@ -78,7 +78,7 @@ OBJ =\
multimeval.o\
rawmemcasechr.o\
rawmemchr.o\
- rawmemrchr.o\
+ rawmemrcasechr.o\
rawmemrchr.o\
strcasechr.o\
strcasechrnul.o\
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 9f2f9a3..dbfbbc5 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -112,6 +112,28 @@ void *libsimple_rawmemrchr(const void *, int, size_t);
/**
+ * Finds the last occurence of a byte value in an array of bytes,
+ * the comparison is case-insensitive
+ *
+ * This function is optimised for instances where it is already
+ * known that there is at least one occurence; if is no occurence
+ * of the specified byte value in the specified byte array, this
+ * behaviour is undefined
+ *
+ * @param s The array of bytes to search
+ * @param c The byte value to search for
+ * @param n The number of bytes in the byte array
+ * @return `s` with a maximal offset such that `tolower(*r) == tolower(c)`,
+ * where `r` is the returned pointer
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
+void *libsimple_rawmemrcasechr(const void *, int, size_t);
+#ifndef rawmemrcasechr
+# define rawmemrcasechr libsimple_rawmemrcasechr
+#endif
+
+
+/**
* Finds the first substring in an array of bytes, the comparison is case-sensitive
*
* @param haystack The array of bytes to search
diff --git a/man/libsimple_memends.3 b/man/libsimple_memends.3
index 8ab4f81..201788e 100644
--- a/man/libsimple_memends.3
+++ b/man/libsimple_memends.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMENDS 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMENDS 3 2018-10-21 libsimple
.SH NAME
libsimple_memends \- checks end of memory
.SH SYNOPSIS
diff --git a/man/libsimple_memeq.3 b/man/libsimple_memeq.3
index 1deca9c..0b9ce1e 100644
--- a/man/libsimple_memeq.3
+++ b/man/libsimple_memeq.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMEQ 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMEQ 3 2018-10-21 libsimple
.SH NAME
libsimple_memeq \- check two memory segments for equality
.SH SYNOPSIS
diff --git a/man/libsimple_memmem.3 b/man/libsimple_memmem.3
index 15437cd..05f9f37 100644
--- a/man/libsimple_memmem.3
+++ b/man/libsimple_memmem.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMMEM 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMMEM 3 2018-10-21 libsimple
.SH NAME
libsimple_memmem \- find byte string in memory
.SH SYNOPSIS
diff --git a/man/libsimple_memrcasechr.3 b/man/libsimple_memrcasechr.3
index be5b748..caf7868 100644
--- a/man/libsimple_memrcasechr.3
+++ b/man/libsimple_memrcasechr.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMRCASECHR 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMRCASECHR 3 2018-10-21 libsimple
.SH NAME
libsimple_memrcasechr \- find byte in memory
.SH SYNOPSIS
diff --git a/man/libsimple_memrchr.3 b/man/libsimple_memrchr.3
index 958fbc9..3aa2214 100644
--- a/man/libsimple_memrchr.3
+++ b/man/libsimple_memrchr.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMRCHR 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMRCHR 3 2018-10-21 libsimple
.SH NAME
libsimple_memrchr \- find byte in memory
.SH SYNOPSIS
diff --git a/man/libsimple_memrmem.3 b/man/libsimple_memrmem.3
index 8ee94c2..f7d9945 100644
--- a/man/libsimple_memrmem.3
+++ b/man/libsimple_memrmem.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMRMEM 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMRMEM 3 2018-10-21 libsimple
.SH NAME
libsimple_memrmem \- find byte string in memory
.SH SYNOPSIS
diff --git a/man/libsimple_memstarts.3 b/man/libsimple_memstarts.3
index 13713a2..f031837 100644
--- a/man/libsimple_memstarts.3
+++ b/man/libsimple_memstarts.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMSTARTS 3 2018-10-20 libsimple
+.TH LIBSIMPLE_MEMSTARTS 3 2018-10-21 libsimple
.SH NAME
libsimple_memstarts \- checks beginning of memory
.SH SYNOPSIS
diff --git a/man/libsimple_rawmemcasechr.3 b/man/libsimple_rawmemcasechr.3
index 3759cd0..4c3129c 100644
--- a/man/libsimple_rawmemcasechr.3
+++ b/man/libsimple_rawmemcasechr.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_RAWMEMCASECHR 3 2018-10-20 libsimple
+.TH LIBSIMPLE_RAWMEMCASECHR 3 2018-10-21 libsimple
.SH NAME
libsimple_rawmemcasechr \- find byte in memory
.SH SYNOPSIS
diff --git a/man/libsimple_rawmemchr.3 b/man/libsimple_rawmemchr.3
index 0425d9a..79b480e 100644
--- a/man/libsimple_rawmemchr.3
+++ b/man/libsimple_rawmemchr.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_RAWMEMCHR 3 2018-10-20 libsimple
+.TH LIBSIMPLE_RAWMEMCHR 3 2018-10-21 libsimple
.SH NAME
libsimple_rawmemchr \- find byte in memory
.SH SYNOPSIS
diff --git a/man/libsimple_rawmemrcasechr.3 b/man/libsimple_rawmemrcasechr.3
new file mode 100644
index 0000000..389b332
--- /dev/null
+++ b/man/libsimple_rawmemrcasechr.3
@@ -0,0 +1,83 @@
+.TH LIBSIMPLE_RAWMEMRCASECHR 3 2018-10-21 libsimple
+.SH NAME
+libsimple_rawmemrcasechr \- find byte in memory
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+void *libsimple_rawmemrcasechr(const void *s, int c, size_t n);
+
+#ifndef rawmemrcasechr
+# define rawmemrcasechr libsimple_rawmemrcasechr
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_rawmemrcasechr ()
+function scans the memory segment
+.IR s ,
+with the size
+.IR n ,
+for the last occurence of the byte
+.I c
+(it is converted to a
+.BR char ).
+.PP
+The
+.BR libsimple_rawmemrcasechr ()
+function assumes there is at least one
+occurence, its behaviour is undefined
+if this is not the case.
+.PP
+The comparison is case-insensitive.
+.SH RETURN VALUE
+The
+.BR libsimple_rawmemrcasechr ()
+function returns the pointer
+.I s
+with a maximal offset such that
+.IR tolower(*r)==tolower(c) ,
+where
+.I r
+is the returned pointer.
+.SH ERRORS
+The
+.BR libsimple_rawmemrcasechr ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_rawmemrcasechr ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_rawmemrcasechr ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_rawmemrcasechr ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_rawmemrchr (3),
+.BR libsimple_memrcasechr (3),
+.BR libsimple_rawmemcasechr (3)
diff --git a/man/libsimple_rawmemrchr.3 b/man/libsimple_rawmemrchr.3
index 198daa6..f4ae624 100644
--- a/man/libsimple_rawmemrchr.3
+++ b/man/libsimple_rawmemrchr.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_RAWMEMRCHR 3 2018-10-20 libsimple
+.TH LIBSIMPLE_RAWMEMRCHR 3 2018-10-21 libsimple
.SH NAME
libsimple_rawmemrchr \- find byte in memory
.SH SYNOPSIS
@@ -78,5 +78,6 @@ None.
.SH BUGS
None.
.SH SEE ALSO
+.BR libsimple_rawmemrcasechr (3),
.BR libsimple_memrchr (3),
.BR libsimple_rawmemchr (3)
diff --git a/rawmemrcasechr.c b/rawmemrcasechr.c
new file mode 100644
index 0000000..68c5645
--- /dev/null
+++ b/rawmemrcasechr.c
@@ -0,0 +1,33 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+#ifndef TEST
+
+
+void *
+libsimple_rawmemrcasechr(const void *s_, int c, size_t n)
+{
+ char *s = *(char **)(void *)&s_;
+ c = tolower(c);
+ while (--n, tolower(s[n]) != c);
+ return &s[n];
+}
+
+
+#else
+#include "test.h"
+
+int
+main(void)
+{
+ assert(!strcmpnul(libsimple_rawmemrcasechr("abcABCabcABC", 'a', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("abcABCabcABC", 'c', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("abcABCabcABC", 'A', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("abcABCabcABC", 'C', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("ABCabcABCabc", 'a', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("ABCabcABCabc", 'c', sizeof("ABCabcABCabc") - 1), "c"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("ABCabcABCabc", 'A', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_rawmemrcasechr("ABCabcABCabc", 'C', sizeof("ABCabcABCabc") - 1), "c"));
+ return 0;
+}
+
+#endif
diff --git a/rawmemrchr.c b/rawmemrchr.c
index 3731c00..80ddc41 100644
--- a/rawmemrchr.c
+++ b/rawmemrchr.c
@@ -18,8 +18,14 @@ libsimple_rawmemrchr(const void *s_, int c_, size_t n)
int
main(void)
{
- assert(!strcmpnul(libsimple_rawmemrchr("1234512345", '3', sizeof("1234512345") - 1), "345"));
- assert(!strcmpnul(libsimple_rawmemrchr("1234512345", '5', sizeof("1234512345") - 1), "5"));
+ assert(!strcmpnul(libsimple_rawmemrchr("abcABCabcABC", 'a', sizeof("abcABCabcABC") - 1), "abcABC"));
+ assert(!strcmpnul(libsimple_rawmemrchr("abcABCabcABC", 'c', sizeof("abcABCabcABC") - 1), "cABC"));
+ assert(!strcmpnul(libsimple_rawmemrchr("abcABCabcABC", 'A', sizeof("abcABCabcABC") - 1), "ABC"));
+ assert(!strcmpnul(libsimple_rawmemrchr("abcABCabcABC", 'C', sizeof("abcABCabcABC") - 1), "C"));
+ assert(!strcmpnul(libsimple_rawmemrchr("ABCabcABCabc", 'a', sizeof("ABCabcABCabc") - 1), "abc"));
+ assert(!strcmpnul(libsimple_rawmemrchr("ABCabcABCabc", 'c', sizeof("ABCabcABCabc") - 1), "c"));
+ assert(!strcmpnul(libsimple_rawmemrchr("ABCabcABCabc", 'A', sizeof("ABCabcABCabc") - 1), "ABCabc"));
+ assert(!strcmpnul(libsimple_rawmemrchr("ABCabcABCabc", 'C', sizeof("ABCabcABCabc") - 1), "Cabc"));
return 0;
}