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/src/utils.c b/src/utils.c
index b8b4ef5..9ab990a 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -928,4 +928,18 @@
 	return (sum * 9) % 10 + '0';
 }
 
+/*! Compare start of a string.
+ * This is an optimisation of 'strstr(str, startswith_str) == str' because it doesn't search through the entire string.
+ * \param str  (Longer) string to compare.
+ * \param startswith_str  (Shorter) string to compare with the start of str.
+ * \return true iff the first characters of str fully match startswith_str or startswith_str is empty. */
+bool osmo_str_startswith(const char *str, const char *startswith_str)
+{
+	if (!startswith_str || !*startswith_str)
+		return true;
+	if (!str)
+		return false;
+	return strncmp(str, startswith_str, strlen(startswith_str)) == 0;
+}
+
 /*! @} */