add osmo_str_startswith()

Move from a static implementation in tdef_vty.c to utils.c, I also want to use
this in osmo-msc.

The point is that the telnet VTY allows unambiguous partly matches of keyword
args. For example, if I have a command definition of:

    compare (apples|oranges)

then it is perfectly legal as for the vty parser to write only

    compare app

One could expect the VTY to then pass the unambiguous match of "apples" to the
parsing function, but that is not the case.

Hence a VTY function implementation is faced with parsing a keyword of "app"
instead of the expected "apples".

This is actually a very widespread bug in our VTY implementations, which assume
that exactly one full keyword will always be found. I am now writing new
commands in a way that are able to manage only the starts of keywords.

Arguably, strstr(a, b) == a does the same thing, but it searches the entire
string unnecessarily.

Change-Id: Ib2ffb0e9a870dd52e081c7e66d8818057d159513
diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c
index 711d6e1..211b4d1 100644
--- a/tests/utils/utils_test.c
+++ b/tests/utils/utils_test.c
@@ -1014,6 +1014,33 @@
 	printf("(need %d chars, had size=63) %s\n", rc, buf);
 }
 
+static void startswith_test_str(const char *str, const char *startswith_str, bool expect_rc)
+{
+	bool rc = osmo_str_startswith(str, startswith_str);
+	printf("osmo_str_startswith(%s, ", osmo_quote_str(str, -1));
+	printf("%s) == %s\n", osmo_quote_str(startswith_str, -1), rc ? "true" : "false");
+	if (rc != expect_rc)
+		printf("   ERROR: EXPECTED %s\n", expect_rc ? "true" : "false");
+}
+
+static void startswith_test()
+{
+	printf("\n%s()\n", __func__);
+	startswith_test_str(NULL, NULL, true);
+	startswith_test_str("", NULL, true);
+	startswith_test_str(NULL, "", true);
+	startswith_test_str("", "", true);
+	startswith_test_str("abc", NULL, true);
+	startswith_test_str("abc", "", true);
+	startswith_test_str(NULL, "abc", false);
+	startswith_test_str("", "abc", false);
+	startswith_test_str("abc", "a", true);
+	startswith_test_str("abc", "ab", true);
+	startswith_test_str("abc", "abc", true);
+	startswith_test_str("abc", "abcd", false);
+	startswith_test_str("abc", "xyz", false);
+}
+
 int main(int argc, char **argv)
 {
 	static const struct log_info log_info = {};
@@ -1032,5 +1059,6 @@
 	osmo_sockaddr_to_str_and_uint_test();
 	osmo_str_tolowupper_test();
 	strbuf_test();
+	startswith_test();
 	return 0;
 }