}
int pakfire_string_endswith(const char* s, const char* suffix) {
+ // Validate input
+ if (!s || !suffix) {
+ errno = EINVAL;
+ return 1;
+ }
+
return !strcmp(s + strlen(s) - strlen(suffix), suffix);
}
return EXIT_FAILURE;
}
+static int test_string_endswith(const struct test* t) {
+ ASSERT_TRUE(pakfire_string_endswith("ABC", "C"));
+ ASSERT_FALSE(pakfire_string_endswith("ABC", "B"));
+
+ // Check for invalid inputs
+ ASSERT_ERRNO(pakfire_string_endswith("ABC", NULL), EINVAL);
+ ASSERT_ERRNO(pakfire_string_endswith(NULL, "ABC"), EINVAL);
+ ASSERT_ERRNO(pakfire_string_endswith(NULL, NULL), EINVAL);
+
+ return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
+}
+
static int test_string_partition(const struct test* t) {
char* part1;
char* part2;
testsuite_add_test(test_basename);
testsuite_add_test(test_dirname);
testsuite_add_test(test_string_startswith);
+ testsuite_add_test(test_string_endswith);
testsuite_add_test(test_string_partition);
testsuite_add_test(test_string_replace);
testsuite_add_test(test_string_split);