blob: d609a3d93cfcb71bb24701bbd82996ae6ab38970 (
plain)
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
|
#include <string.h>
#include "_safety.h"
/** compare strings **/
int strcmp(const char *s1, const char *s2)
{
SIGNAL_SAFE(0);
ASSERT_NONNULL(s1);
ASSERT_NONNULL(s2);
/* TODO: dangerous read * 2 */
/* no modifcation, overlap is OK */
while (*s1 && *s2) {
if (*s1 != *s2) {
return *s1 - *s2;
}
s1++;
s2++;
}
/*
RETURN(NEGATIVE, ARGUMENT(s1) is less than ARGUMENT(s2));
RETURN(ZERO, ARGUMENT(s1) is equal to ARGUMENT(s2));
RETURN(POSITIVE, ARGUMENT(s1) is greater than ARGUMENT(s2));
*/
if (*s1) {
return -1;
}
if (*s2) {
return 1;
}
return 0;
}
CHECK_2(int, 0, strcmp, const char *, const char *)
/***
compares the strings at ARGUMENT(s1) and ARGUMENT(s2).
***/
/*
STDC(1)
*/
|