blob: aaf97e604a15528b423cade512f8658a5c85ebfc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include "common/memrchr.h"
#include <stddef.h>
#include <stdint.h>
void* memrchr(const void* s, int c, size_t n) {
if (n == 0) {
return NULL;
}
const uint8_t uc = (uint8_t) c;
const uint8_t* p = (const uint8_t*) s + n;
while (n--) {
if (*--p == uc) {
return (void*) p;
}
}
return NULL;
}
|