aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string/strrchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string/strrchr.c')
-rw-r--r--lib/libc/string/strrchr.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/libc/string/strrchr.c b/lib/libc/string/strrchr.c
new file mode 100644
index 0000000..ccfaa9f
--- /dev/null
+++ b/lib/libc/string/strrchr.c
@@ -0,0 +1,28 @@
+/******************************************************************************
+ * libc strrchr() implementation
+ *
+ * This program and the accompanying materials are made available under
+ * the terms of the BSD License which accompanies this distribution, and
+ * is available at http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * Thomas Huth - initial implementation
+ *****************************************************************************/
+
+#include <string.h>
+
+char *
+strrchr(const char *s, int c)
+{
+ char cb = c;
+ char *ptr = (char *)s + strlen(s) - 1;
+
+ while (ptr >= s) {
+ if (*ptr == cb) {
+ return ptr;
+ }
+ --ptr;
+ }
+
+ return NULL;
+}