-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
41 lines (39 loc) · 1001 Bytes
/
Copy pathutil.c
File metadata and controls
41 lines (39 loc) · 1001 Bytes
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
//
// Created by ganquan on 2020/4/16.
//
#include "util.h"
int keyCompare(unsigned char *c1, unsigned char *c2, int l1, int l2) {
uint8_t *s1 = c1;
uint8_t *s2 = c2;
for(; l1>0 && l2>0 ; s1++, s2++, l1--, l2--) {
if(*s1 != *s2) {
return (*s1 > *s2) ? 1 : -1;
}
}
if (l1 == l2) return 0;
if (l1 > 0) return 1;
return -1;
}
int keyCompareWithMove(uint8_t **c1, uint8_t *c2, int l1, int l2) {
if (l1 == 0 && l2 != 0) return -1;
// if (l2 == 0 && l1 != 0) return 1;
for(; l1>0 && l2>0 ; (*c1)++, c2++, l1--, l2--) {
if(**c1 != *c2) {
return (**c1 > *c2) ? 1 : -1;
}
}
if (l2 > 0 && 0 == l1) return -1;
// else if (l2 > 0) return -1;
return 0;
}
int keyContain(uint8_t *c1, uint8_t *c2, int l1, int l2) {
if (l1 < l2) return 0;
uint8_t *s1 = c1;
uint8_t *s2 = c2;
for(; l2>0 ; s1++, s2++, l2--) {
if(*s1 != *s2) {
return 0;
}
}
return 1;
}