Renamed ssequal() to isprefix(), because that's what it checks.
[mmh] / sbr / isprefix.c
diff --git a/sbr/isprefix.c b/sbr/isprefix.c
new file mode 100644 (file)
index 0000000..33c0699
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+** isprefix.c -- check if a string is a PREFIX of another
+**
+** This code is Copyright (c) 2002, by the authors of nmh.  See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
+
+#include <h/mh.h>
+
+/*
+** This function had been named ssequal(). It had advertised it would
+** check for substring matching, but actually checked prefix matching.
+** The latter being the thing wanted. Hence, only the name and the
+** descriptions were wrong. I fixed this.
+** -- markus schnalke <meillo@marmaro.de>, 2011-11
+*/
+
+/*
+** Check if s1 is a PREFIX of s2.
+** If yes, then return 1, else return 0.
+*/
+int
+isprefix(char *s1, char *s2)
+{
+       if (!s1)
+               s1 = "";
+       if (!s2)
+               s2 = "";
+
+       while (*s1)
+               if (*s1++ != *s2++)
+                       return 0;
+       return 1;
+}