options/posix: Implement memrchr
@@ -121,7 +121,13 @@ char *strndupa(const char *, size_t) {
__builtin_unreachable();
}
-void *memrchr(const void *, int, size_t) {
- __ensure(!"Not implemented");
- __builtin_unreachable();
+// This implementation was taken from musl
+void *memrchr(const void *m, int c, size_t n) {
+ const unsigned char *s = (const unsigned char *)m;
+ c = (unsigned char)c;
+ while(n--) {
+ if(s[n] == c)
+ return (void *)(s + n);
+ }
+ return 0;
}
