-
Notifications
You must be signed in to change notification settings - Fork 12
/
main_memrchr.c
53 lines (36 loc) · 845 Bytes
/
main_memrchr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <assert.h>
#include <stdio.h>
void *memrchr(const void *src, int c, size_t n);
int main()
{
char v[4096] = {0};
v[0] = 'X';
char *p;
p = memrchr(v, ' ', sizeof v);
assert(!p);
p = memrchr(v, 'X', sizeof v);
assert(p == v);
v[255] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+255);
v[255] = ' ';
v[256] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+256);
v[255] = 'X';
v[256] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+256);
v[500] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+500);
v[511] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+511);
v[512] = 'X';
p = memrchr(v, 'X', sizeof v);
assert(p == v+512);
p = memrchr(v, 'X', 512);
assert(p == v+511);
return 0;
}