Walk the grant file, invoking visit for each entry. visit returns true to stop. * Returns the number of entries seen. */
| 348 | /* Walk the grant file, invoking visit for each entry. visit returns true to stop. |
| 349 | * Returns the number of entries seen. */ |
| 350 | static int ws_grant_walk(const char *cache_dir, |
| 351 | bool (*visit)(const char *root, bool sensitive, void *ctx), void *ctx) { |
| 352 | char store[WS_LINE_MAX]; |
| 353 | if (!cbm_workspace_grant_path(cache_dir, store, sizeof(store))) { |
| 354 | return 0; |
| 355 | } |
| 356 | FILE *f = cbm_fopen(store, "r"); |
| 357 | if (!f) { |
| 358 | return 0; |
| 359 | } |
| 360 | char line[WS_LINE_MAX]; |
| 361 | int seen = 0; |
| 362 | while (fgets(line, (int)sizeof(line), f)) { |
| 363 | size_t len = strlen(line); |
| 364 | while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) { |
| 365 | line[--len] = '\0'; |
| 366 | } |
| 367 | if (len == 0 || line[0] == '#') { |
| 368 | continue; |
| 369 | } |
| 370 | bool sensitive = line[0] == WS_SENSITIVE_MARK; |
| 371 | const char *root = sensitive ? line + 1 : line; |
| 372 | if (!root[0]) { |
| 373 | continue; |
| 374 | } |
| 375 | seen++; |
| 376 | if (visit && visit(root, sensitive, ctx)) { |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | (void)fclose(f); |
| 381 | return seen; |
| 382 | } |
| 383 | |
| 384 | typedef struct { |
| 385 | const char *candidate; |
no test coverage detected