| 262 | }; |
| 263 | |
| 264 | static int check_entry_match(const char *a, int a_len, const char *b, int b_len) |
| 265 | { |
| 266 | /* |
| 267 | * The caller wants to pick *a* from a tree or nothing. |
| 268 | * We are looking at *b* in a tree. |
| 269 | * |
| 270 | * (0) If a and b are the same name, we are trivially happy. |
| 271 | * |
| 272 | * There are three possibilities where *a* could be hiding |
| 273 | * behind *b*. |
| 274 | * |
| 275 | * (1) *a* == "t", *b* == "ab" i.e. *b* sorts earlier than *a* no |
| 276 | * matter what. |
| 277 | * (2) *a* == "t", *b* == "t-2" and "t" is a subtree in the tree; |
| 278 | * (3) *a* == "t-2", *b* == "t" and "t-2" is a blob in the tree. |
| 279 | * |
| 280 | * Otherwise we know *a* won't appear in the tree without |
| 281 | * scanning further. |
| 282 | */ |
| 283 | |
| 284 | int cmp = name_compare(a, a_len, b, b_len); |
| 285 | |
| 286 | /* Most common case first -- reading sync'd trees */ |
| 287 | if (!cmp) |
| 288 | return cmp; |
| 289 | |
| 290 | if (0 < cmp) { |
| 291 | /* a comes after b; it does not matter if it is case (3) |
| 292 | if (b_len < a_len && !memcmp(a, b, b_len) && a[b_len] < '/') |
| 293 | return 1; |
| 294 | */ |
| 295 | return 1; /* keep looking */ |
| 296 | } |
| 297 | |
| 298 | /* b comes after a; are we looking at case (2)? */ |
| 299 | if (a_len < b_len && !memcmp(a, b, a_len) && b[a_len] < '/') |
| 300 | return 1; /* keep looking */ |
| 301 | |
| 302 | return -1; /* a cannot appear in the tree */ |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * From the extended tree_desc, extract the first name entry, while |
no test coverage detected