aboutsummaryrefslogtreecommitdiffstats
path: root/strnend.c
diff options
context:
space:
mode:
Diffstat (limited to 'strnend.c')
-rw-r--r--strnend.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/strnend.c b/strnend.c
new file mode 100644
index 0000000..df950cf
--- /dev/null
+++ b/strnend.c
@@ -0,0 +1,38 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.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