Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | #include <config.h> | - |
20 | #include "filevercmp.h" | - |
21 | | - |
22 | #include <sys/types.h> | - |
23 | #include <stdlib.h> | - |
24 | #include <stdbool.h> | - |
25 | #include <string.h> | - |
26 | #include <c-ctype.h> | - |
27 | #include <limits.h> | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | static const char * | - |
34 | match_suffix (const char **str) | - |
35 | { | - |
36 | const char *match = NULL; | - |
37 | bool read_alpha = false; | - |
38 | while (**str)TRUE | evaluated 6446 times by 2 tests | FALSE | evaluated 336 times by 2 tests |
| 336-6446 |
39 | { | - |
40 | if (read_alpha)TRUE | evaluated 586 times by 2 tests | FALSE | evaluated 5860 times by 2 tests |
| 586-5860 |
41 | { | - |
42 | read_alpha = false; | - |
43 | if (!c_isalpha (**str) && '~' != **str)TRUE | evaluated 387 times by 2 tests | FALSE | evaluated 199 times by 1 test |
TRUE | evaluated 379 times by 2 tests | FALSE | evaluated 8 times by 1 test |
| 8-387 |
44 | match = NULL;executed 379 times by 2 tests: match = ((void *)0) ; | 379 |
45 | }executed 586 times by 2 tests: end of block | 586 |
46 | else if ('.' == **str)TRUE | evaluated 586 times by 2 tests | FALSE | evaluated 5274 times by 2 tests |
| 586-5274 |
47 | { | - |
48 | read_alpha = true; | - |
49 | if (!match)TRUE | evaluated 480 times by 2 tests | FALSE | evaluated 106 times by 1 test |
| 106-480 |
50 | match = *str;executed 480 times by 2 tests: match = *str; | 480 |
51 | }executed 586 times by 2 tests: end of block | 586 |
52 | else if (!c_isalnum (**str) && '~' != **str)TRUE | evaluated 933 times by 2 tests | FALSE | evaluated 4341 times by 2 tests |
TRUE | evaluated 917 times by 1 test | FALSE | evaluated 16 times by 1 test |
| 16-4341 |
53 | match = NULL;executed 917 times by 1 test: match = ((void *)0) ; | 917 |
54 | (*str)++; | - |
55 | }executed 6446 times by 2 tests: end of block | 6446 |
56 | return match;executed 336 times by 2 tests: return match; | 336 |
57 | } | - |
58 | | - |
59 | | - |
60 | static int | - |
61 | order (unsigned char c) | - |
62 | { | - |
63 | if (c_isdigit (c))TRUE | evaluated 20 times by 2 tests | FALSE | evaluated 2132 times by 2 tests |
| 20-2132 |
64 | return 0;executed 20 times by 2 tests: return 0; | 20 |
65 | else if (c_isalpha (c))TRUE | evaluated 1689 times by 2 tests | FALSE | evaluated 443 times by 2 tests |
| 443-1689 |
66 | return c;executed 1689 times by 2 tests: return c; | 1689 |
67 | else if (c == '~')TRUE | evaluated 4 times by 1 test | FALSE | evaluated 439 times by 2 tests |
| 4-439 |
68 | return -1;executed 4 times by 1 test: return -1; | 4 |
69 | else | - |
70 | return (int) c + UCHAR_MAX + 1;executed 439 times by 2 tests: return (int) c + (0x7f * 2 + 1) + 1; | 439 |
71 | } | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | static int _GL_ATTRIBUTE_PURE | - |
84 | verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) | - |
85 | { | - |
86 | size_t s1_pos = 0; | - |
87 | size_t s2_pos = 0; | - |
88 | while (s1_pos < s1_len || s2_pos < s2_len)TRUE | evaluated 229 times by 2 tests | FALSE | evaluated 4 times by 1 test |
TRUE | evaluated 4 times by 1 test | FALSE | never evaluated |
| 0-229 |
89 | { | - |
90 | int first_diff = 0; | - |
91 | while ((s1_pos < s1_len && !c_isdigit (s1[s1_pos]))TRUE | evaluated 1196 times by 2 tests | FALSE | evaluated 20 times by 2 tests |
TRUE | evaluated 1048 times by 2 tests | FALSE | evaluated 148 times by 2 tests |
| 20-1196 |
92 | || (s2_pos < s2_len && !c_isdigit (s2[s2_pos])))TRUE | evaluated 168 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 40 times by 2 tests | FALSE | evaluated 128 times by 2 tests |
| 0-168 |
93 | { | - |
94 | int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]);TRUE | evaluated 20 times by 2 tests | FALSE | evaluated 1068 times by 2 tests |
| 20-1068 |
95 | int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]);TRUE | evaluated 4 times by 1 test | FALSE | evaluated 1084 times by 2 tests |
| 4-1084 |
96 | if (s1_c != s2_c)TRUE | evaluated 105 times by 2 tests | FALSE | evaluated 983 times by 2 tests |
| 105-983 |
97 | return s1_c - s2_c;executed 105 times by 2 tests: return s1_c - s2_c; | 105 |
98 | s1_pos++; | - |
99 | s2_pos++; | - |
100 | }executed 983 times by 2 tests: end of block | 983 |
101 | while (s1[s1_pos] == '0')TRUE | evaluated 12 times by 2 tests | FALSE | evaluated 128 times by 2 tests |
| 12-128 |
102 | s1_pos++;executed 12 times by 2 tests: s1_pos++; | 12 |
103 | while (s2[s2_pos] == '0')TRUE | evaluated 2 times by 1 test | FALSE | evaluated 128 times by 2 tests |
| 2-128 |
104 | s2_pos++;executed 2 times by 1 test: s2_pos++; | 2 |
105 | while (c_isdigit (s1[s1_pos]) && c_isdigit (s2[s2_pos]))TRUE | evaluated 150 times by 1 test | FALSE | evaluated 109 times by 2 tests |
TRUE | evaluated 131 times by 1 test | FALSE | evaluated 19 times by 1 test |
| 19-150 |
106 | { | - |
107 | if (!first_diff)TRUE | evaluated 119 times by 1 test | FALSE | evaluated 12 times by 1 test |
| 12-119 |
108 | first_diff = s1[s1_pos] - s2[s2_pos];executed 119 times by 1 test: first_diff = s1[s1_pos] - s2[s2_pos]; | 119 |
109 | s1_pos++; | - |
110 | s2_pos++; | - |
111 | }executed 131 times by 1 test: end of block | 131 |
112 | if (c_isdigit (s1[s1_pos]))TRUE | evaluated 19 times by 1 test | FALSE | evaluated 109 times by 2 tests |
| 19-109 |
113 | return 1;executed 19 times by 1 test: return 1; | 19 |
114 | if (c_isdigit (s2[s2_pos]))TRUE | evaluated 16 times by 2 tests | FALSE | evaluated 93 times by 1 test |
| 16-93 |
115 | return -1;executed 16 times by 2 tests: return -1; | 16 |
116 | if (first_diff)TRUE | evaluated 28 times by 1 test | FALSE | evaluated 65 times by 1 test |
| 28-65 |
117 | return first_diff;executed 28 times by 1 test: return first_diff; | 28 |
118 | }executed 65 times by 1 test: end of block | 65 |
119 | return 0; never executed: return 0; | 0 |
120 | } | - |
121 | | - |
122 | | - |
123 | | - |
124 | int | - |
125 | filevercmp (const char *s1, const char *s2) | - |
126 | { | - |
127 | const char *s1_pos; | - |
128 | const char *s2_pos; | - |
129 | const char *s1_suffix, *s2_suffix; | - |
130 | size_t s1_len, s2_len; | - |
131 | int result; | - |
132 | | - |
133 | | - |
134 | int simple_cmp = strcmp (s1, s2); never executed: __result = (((const unsigned char *) (const char *) ( s1 ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( s2 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
135 | if (simple_cmp == 0)TRUE | evaluated 21 times by 1 test | FALSE | evaluated 188 times by 2 tests |
| 21-188 |
136 | return 0;executed 21 times by 1 test: return 0; | 21 |
137 | | - |
138 | | - |
139 | if (!*s1)TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
| 0-188 |
140 | return -1; never executed: return -1; | 0 |
141 | if (!*s2)TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
| 0-188 |
142 | return 1; never executed: return 1; | 0 |
143 | if (0 == strcmp (".", s1)) never executed: __result = (((const unsigned char *) (const char *) ( "." ))[3] - __s2[3]); never executed: end of block executed 50 times by 1 test: end of block never executed: __result = (((const unsigned char *) (const char *) ( s1 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
TRUE | evaluated 188 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 50 times by 1 test | FALSE | evaluated 138 times by 2 tests |
TRUE | never evaluated | FALSE | evaluated 50 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-188 |
144 | return -1; never executed: return -1; | 0 |
145 | if (0 == strcmp (".", s2)) never executed: __result = (((const unsigned char *) (const char *) ( "." ))[3] - __s2[3]); never executed: end of block executed 30 times by 1 test: end of block never executed: __result = (((const unsigned char *) (const char *) ( s2 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
TRUE | evaluated 188 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 30 times by 1 test | FALSE | evaluated 158 times by 2 tests |
TRUE | never evaluated | FALSE | evaluated 30 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-188 |
146 | return 1; never executed: return 1; | 0 |
147 | if (0 == strcmp ("..", s1)) never executed: __result = (((const unsigned char *) (const char *) ( ".." ))[3] - __s2[3]); never executed: end of block executed 50 times by 1 test: end of block never executed: __result = (((const unsigned char *) (const char *) ( s1 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
TRUE | evaluated 188 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 50 times by 1 test | FALSE | evaluated 138 times by 2 tests |
TRUE | evaluated 50 times by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 50 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-188 |
148 | return -1; never executed: return -1; | 0 |
149 | if (0 == strcmp ("..", s2)) never executed: __result = (((const unsigned char *) (const char *) ( ".." ))[3] - __s2[3]); never executed: end of block executed 30 times by 1 test: end of block never executed: __result = (((const unsigned char *) (const char *) ( s2 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | never evaluated | FALSE | evaluated 188 times by 2 tests |
TRUE | evaluated 188 times by 2 tests | FALSE | never evaluated |
TRUE | evaluated 30 times by 1 test | FALSE | evaluated 158 times by 2 tests |
TRUE | evaluated 30 times by 1 test | FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 30 times by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-188 |
150 | return 1; never executed: return 1; | 0 |
151 | | - |
152 | | - |
153 | if (*s1 == '.' && *s2 != '.')TRUE | evaluated 50 times by 1 test | FALSE | evaluated 138 times by 2 tests |
TRUE | evaluated 20 times by 1 test | FALSE | evaluated 30 times by 1 test |
| 20-138 |
154 | return -1;executed 20 times by 1 test: return -1; | 20 |
155 | if (*s1 != '.' && *s2 == '.')TRUE | evaluated 138 times by 2 tests | FALSE | evaluated 30 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 138 times by 2 tests |
| 0-138 |
156 | return 1; never executed: return 1; | 0 |
157 | if (*s1 == '.' && *s2 == '.')TRUE | evaluated 30 times by 1 test | FALSE | evaluated 138 times by 2 tests |
TRUE | evaluated 30 times by 1 test | FALSE | never evaluated |
| 0-138 |
158 | { | - |
159 | s1++; | - |
160 | s2++; | - |
161 | }executed 30 times by 1 test: end of block | 30 |
162 | | - |
163 | | - |
164 | s1_pos = s1; | - |
165 | s2_pos = s2; | - |
166 | s1_suffix = match_suffix (&s1_pos); | - |
167 | s2_suffix = match_suffix (&s2_pos); | - |
168 | s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1;TRUE | evaluated 60 times by 2 tests | FALSE | evaluated 108 times by 2 tests |
| 60-108 |
169 | s2_len = (s2_suffix ? s2_suffix : s2_pos) - s2;TRUE | evaluated 41 times by 2 tests | FALSE | evaluated 127 times by 2 tests |
| 41-127 |
170 | | - |
171 | | - |
172 | if ((s1_suffix || s2_suffix) && (s1_len == s2_len)TRUE | evaluated 60 times by 2 tests | FALSE | evaluated 108 times by 2 tests |
TRUE | evaluated 4 times by 1 test | FALSE | evaluated 104 times by 2 tests |
TRUE | evaluated 5 times by 2 tests | FALSE | evaluated 59 times by 2 tests |
| 4-108 |
173 | && 0 == strncmp (s1, s2, s1_len)) never executed: __result = (((const unsigned char *) (const char *) ( s1 ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( s2 ))[3] - __s2[3]); never executed: end of block never executed: end of block TRUE | evaluated 4 times by 1 test | FALSE | evaluated 1 time by 1 test |
TRUE | never evaluated | FALSE | evaluated 5 times by 2 tests |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-5 |
174 | { | - |
175 | s1_len = s1_pos - s1; | - |
176 | s2_len = s2_pos - s2; | - |
177 | }executed 4 times by 1 test: end of block | 4 |
178 | | - |
179 | result = verrevcmp (s1, s1_len, s2, s2_len); | - |
180 | return result == 0 ? simple_cmp : result;executed 168 times by 2 tests: return result == 0 ? simple_cmp : result; | 168 |
181 | } | - |
| | |