1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright (c) 2020 Proofpoint, 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>
#include <sm/sendmail.h>
#if USE_EAI
#include <sm/string.h>
#include <sm/heap.h>
#include <sm/ixlen.h>
/*
** SM_STRCASEEQ -- are two strings equal (case-insenstive)?
**
** Parameters:
** s1 -- string
** s2 -- string
**
** Returns:
** true iff s1 == s2
*/
bool
sm_strcaseeq(s1, s2)
const char *s1;
const char *s2;
{
char *l1, *l2;
char *f1;
bool same;
if (asciistr(s1))
{
if (!asciistr(s2))
return false;
return (sm_strcasecmp(s1, s2) == 0);
}
if (asciistr(s2))
return false;
l1 = sm_lowercase(s1);
if (l1 != s1)
{
f1 = sm_strdup_x(l1);
l1 = f1;
}
else
f1 = NULL;
l2 = sm_lowercase(s2);
while (*l1 == *l2 && '\0' != *l1)
l1++, l2++;
same = *l1 == *l2;
SM_FREE(f1);
return same;
}
/*
** SM_STRNCASEEQ -- are two strings (up to a length) equal (case-insenstive)?
**
** Parameters:
** s1 -- string
** s2 -- string
** n -- maximum length to compare
**
** Returns:
** true iff s1 == s2 (for up to the first n char)
*/
bool
sm_strncaseeq(s1, s2, n)
const char *s1;
const char *s2;
size_t n;
{
char *l1, *l2;
char *f1;
bool same;
if (0 == n)
return true;
if (asciistr(s1))
{
if (!asciistr(s2))
return false;
return (sm_strncasecmp(s1, s2, n) == 0);
}
if (asciistr(s2))
return false;
l1 = sm_lowercase(s1);
if (l1 != s1)
{
f1 = sm_strdup_x(l1);
l1 = f1;
}
else
f1 = NULL;
l2 = sm_lowercase(s2);
while (*l1 == *l2 && '\0' != *l1 && n-- > 0)
l1++, l2++;
same = *l1 == *l2;
SM_FREE(f1);
return same;
}
#endif /* USE_EAI */
|