summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm/strrevcmp.c
diff options
context:
space:
mode:
authorgshapiro <gshapiro@FreeBSD.org>2002-02-17 21:56:45 +0000
committergshapiro <gshapiro@FreeBSD.org>2002-02-17 21:56:45 +0000
commit8449595fe97f4474b9b9a7e4edee1ef35dcff393 (patch)
treee7a33b132264d449a512ddf4a8685df097669c1d /contrib/sendmail/libsm/strrevcmp.c
parent289b381b31415647269c7520d881017e2dcb27f1 (diff)
downloadFreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.zip
FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.tar.gz
Import sendmail 8.12.2
Diffstat (limited to 'contrib/sendmail/libsm/strrevcmp.c')
-rw-r--r--contrib/sendmail/libsm/strrevcmp.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/contrib/sendmail/libsm/strrevcmp.c b/contrib/sendmail/libsm/strrevcmp.c
new file mode 100644
index 0000000..d0ed630
--- /dev/null
+++ b/contrib/sendmail/libsm/strrevcmp.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+#include <sm/gen.h>
+SM_RCSID("@(#)$Id: strrevcmp.c,v 1.5 2001/09/11 04:04:49 gshapiro Exp $")
+
+#include <sm/config.h>
+#include <sm/string.h>
+#include <string.h>
+
+/* strcasecmp.c */
+extern const unsigned char charmap[];
+
+/*
+** SM_STRREVCASECMP -- compare two strings starting at the end (ignore case)
+**
+** Parameters:
+** s1 -- first string.
+** s2 -- second string.
+**
+** Returns:
+** strcasecmp(reverse(s1), reverse(s2))
+*/
+
+int
+sm_strrevcasecmp(s1, s2)
+ const char *s1, *s2;
+{
+ register int i1, i2;
+
+ i1 = strlen(s1) - 1;
+ i2 = strlen(s2) - 1;
+ while (i1 >= 0 && i2 >= 0 &&
+ charmap[(unsigned char) s1[i1]] ==
+ charmap[(unsigned char) s2[i2]])
+ {
+ --i1;
+ --i2;
+ }
+ if (i1 < 0)
+ {
+ if (i2 < 0)
+ return 0;
+ else
+ return -1;
+ }
+ else
+ {
+ if (i2 < 0)
+ return 1;
+ else
+ return (charmap[(unsigned char) s1[i1]] -
+ charmap[(unsigned char) s2[i2]]);
+ }
+}
+/*
+** SM_STRREVCMP -- compare two strings starting at the end
+**
+** Parameters:
+** s1 -- first string.
+** s2 -- second string.
+**
+** Returns:
+** strcmp(reverse(s1), reverse(s2))
+*/
+
+int
+sm_strrevcmp(s1, s2)
+ const char *s1, *s2;
+{
+ register int i1, i2;
+
+ i1 = strlen(s1) - 1;
+ i2 = strlen(s2) - 1;
+ while (i1 >= 0 && i2 >= 0 && s1[i1] == s2[i2])
+ {
+ --i1;
+ --i2;
+ }
+ if (i1 < 0)
+ {
+ if (i2 < 0)
+ return 0;
+ else
+ return -1;
+ }
+ else
+ {
+ if (i2 < 0)
+ return 1;
+ else
+ return s1[i1] - s2[i2];
+ }
+}
OpenPOWER on IntegriCloud