Update zoneinfo database.
[dragonfly/netmp.git] / contrib / sendmail / libsm / strrevcmp.c
blobd0ed630eacbd68fa701354f2bd53372fc77d7f98
1 /*
2 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 */
11 #include <sm/gen.h>
12 SM_RCSID("@(#)$Id: strrevcmp.c,v 1.5 2001/09/11 04:04:49 gshapiro Exp $")
14 #include <sm/config.h>
15 #include <sm/string.h>
16 #include <string.h>
18 /* strcasecmp.c */
19 extern const unsigned char charmap[];
22 ** SM_STRREVCASECMP -- compare two strings starting at the end (ignore case)
24 ** Parameters:
25 ** s1 -- first string.
26 ** s2 -- second string.
28 ** Returns:
29 ** strcasecmp(reverse(s1), reverse(s2))
32 int
33 sm_strrevcasecmp(s1, s2)
34 const char *s1, *s2;
36 register int i1, i2;
38 i1 = strlen(s1) - 1;
39 i2 = strlen(s2) - 1;
40 while (i1 >= 0 && i2 >= 0 &&
41 charmap[(unsigned char) s1[i1]] ==
42 charmap[(unsigned char) s2[i2]])
44 --i1;
45 --i2;
47 if (i1 < 0)
49 if (i2 < 0)
50 return 0;
51 else
52 return -1;
54 else
56 if (i2 < 0)
57 return 1;
58 else
59 return (charmap[(unsigned char) s1[i1]] -
60 charmap[(unsigned char) s2[i2]]);
64 ** SM_STRREVCMP -- compare two strings starting at the end
66 ** Parameters:
67 ** s1 -- first string.
68 ** s2 -- second string.
70 ** Returns:
71 ** strcmp(reverse(s1), reverse(s2))
74 int
75 sm_strrevcmp(s1, s2)
76 const char *s1, *s2;
78 register int i1, i2;
80 i1 = strlen(s1) - 1;
81 i2 = strlen(s2) - 1;
82 while (i1 >= 0 && i2 >= 0 && s1[i1] == s2[i2])
84 --i1;
85 --i2;
87 if (i1 < 0)
89 if (i2 < 0)
90 return 0;
91 else
92 return -1;
94 else
96 if (i2 < 0)
97 return 1;
98 else
99 return s1[i1] - s2[i2];