aboutsummaryrefslogtreecommitdiffstats
path: root/strrchr_inv.c
blob: 37b7e79de59b0512f9056105dedd2223111811a9 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
#ifndef TEST


char *
libsimple_strrchr_inv(const char *s_, int c_)
{
	char *s = *(char **)(void *)&s_, c = (char)c_, *r = NULL;
	for (; *s; s++)
		if (*s != c)
			r = s;
	return r;
}


#else
#include "test.h"

int
main(void)
{
	assert(!strcmpnul(libsimple_strrchr_inv("aabbaabb", 'b'), "abb"));
	assert(!strcmpnul(libsimple_strrchr_inv("aabbaabb", 'B'), "b"));
	assert(!strcmpnul(libsimple_strrchr_inv("AABBAABB", 'b'), "B"));
	assert(!strcmpnul(libsimple_strrchr_inv("AABBAABB", 'B'), "ABB"));
	assert(!strcmpnul(libsimple_strrchr_inv("aabbaabb", 'a'), "b"));
	assert(!strcmpnul(libsimple_strrchr_inv("aabbaabb", '\0'), "b"));
	assert(!strcmpnul(libsimple_strrchr_inv("--------", '-'), NULL));
	return 0;
}

#endif