Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
str_ends_with: add a new util function
Baptiste Daroussin committed 1 year ago
commit f398b0be27f3a9af9b566a005a4d52d56c7a4766
parent 00658e1
4 files changed +29 -0
modified libpkg/pkg_solve.c
@@ -672,6 +672,7 @@ pkg_solve_process_universe_variable(struct pkg_solve_problem *problem,

		/* Shlibs */
		tll_foreach(pkg->shlibs_required, s) {
+
			/* Ignore 32 bit libraries */
			if (pkghash_get(j->system_shlibs, s->item) != NULL) {
				/* The shlib is provided by the system */
				continue;
modified libpkg/private/utils.h
@@ -118,5 +118,6 @@ void append_random_suffix(char *buf, int buflen, int suffixlen);
char *json_escape(const char *str);
const char *get_http_auth(void);
bool c_charv_contains(c_charv_t *, const char *, bool);
+
bool str_ends_with(const char *str, const char *end);

#endif
modified libpkg/utils.c
@@ -1019,3 +1019,20 @@ c_charv_contains(c_charv_t *v, const char *el, bool casesensitive)
	}
	return (false);
}
+

+
bool
+
str_ends_with(const char *str, const char *end)
+
{
+
	size_t el, sl;
+

+
	if (end == NULL)
+
		return (true);
+
	if (str == NULL)
+
		return (false);
+

+
	sl = strlen(str);
+
	el = strlen(end);
+
	if (sl < el)
+
		return (false);
+
	return (strncmp(str + (sl - el), end, (sl - el)) == 0);
+
}
modified tests/lib/utils.c
@@ -35,6 +35,7 @@ ATF_TC_WITHOUT_HEAD(random_suffix);
ATF_TC_WITHOUT_HEAD(json_escape);
ATF_TC_WITHOUT_HEAD(open_tempdir);
ATF_TC_WITHOUT_HEAD(get_http_auth);
+
ATF_TC_WITHOUT_HEAD(str_ends_with);

ATF_TC_BODY(hidden_tempfile, tc) {
	const char *filename = "plop";
@@ -126,6 +127,14 @@ ATF_TC_BODY(get_http_auth, tc) {
	ATF_REQUIRE_STREQ(get_http_auth(), "user:passwd");
}

+
ATF_TC_BODY(str_ends_with, tc) {
+
	ATF_REQUIRE(str_ends_with(NULL, NULL));
+
	ATF_REQUIRE(!str_ends_with(NULL, "end"));
+
	ATF_REQUIRE(!str_ends_with("a", "end"));
+
	ATF_REQUIRE(str_ends_with("end", "end"));
+
	ATF_REQUIRE(str_ends_with("backend", "end"));
+
}
+

ATF_TP_ADD_TCS(tp)
{
	ATF_TP_ADD_TC(tp, hidden_tempfile);
@@ -133,6 +142,7 @@ ATF_TP_ADD_TCS(tp)
	ATF_TP_ADD_TC(tp, json_escape);
	ATF_TP_ADD_TC(tp, open_tempdir);
	ATF_TP_ADD_TC(tp, get_http_auth);
+
	ATF_TP_ADD_TC(tp, str_ends_with);

	return (atf_no_error());
}