aboutsummaryrefslogtreecommitdiffstats
path: root/strnend.c
blob: 00687cdb2e288ffba832aca01e2eed2f743778a6 (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
34
35
36
37
38
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


char *
libsimple_strnend(const char *s_, size_t n)
{
	char *s = *(char **)(void *)&s_;
	char *end = &s[n];
	for (; s != end && *s; s++);
	return s;
}


#else
#include "test.h"

int
main(void)
{
	assert(!strcmpnul(libsimple_strnend("123456789", 0), "123456789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 1), "23456789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 2), "3456789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 3), "456789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 4), "56789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 5), "6789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 6), "789"));
	assert(!strcmpnul(libsimple_strnend("123456789", 7), "89"));
	assert(!strcmpnul(libsimple_strnend("123456789", 8), "9"));
	assert(!strcmpnul(libsimple_strnend("123456789", 9), ""));
	assert(!strcmpnul(libsimple_strnend("123456789", 10), ""));
	assert(!strcmpnul(libsimple_strnend("123456789", 11), ""));
	assert(!strcmpnul(libsimple_strnend("123456789", 12), ""));
	return 0;
}

#endif