| 311 | } |
| 312 | |
| 313 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 314 | if (!path) { |
| 315 | return NULL; |
| 316 | } |
| 317 | |
| 318 | FILE *f = cbm_fopen(path, "r"); |
| 319 | if (!f) { |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | /* Read entire file */ |
| 324 | (void)fseek(f, 0, SEEK_END); |
| 325 | long size = ftell(f); |
| 326 | (void)fseek(f, 0, SEEK_SET); |
| 327 | |
| 328 | if (size <= 0) { |
| 329 | (void)fclose(f); |
| 330 | return cbm_gitignore_parse(""); |
| 331 | } |
| 332 | |
| 333 | char *buf = malloc(size + SKIP_ONE); |
| 334 | if (!buf) { |
| 335 | (void)fclose(f); |
| 336 | return NULL; |
| 337 | } |
| 338 | |
| 339 | size_t n = fread(buf, SKIP_ONE, size, f); |
| 340 | buf[n] = '\0'; |
| 341 | (void)fclose(f); |
| 342 | |
| 343 | cbm_gitignore_t *gi = cbm_gitignore_parse(buf); |
| 344 | free(buf); |
| 345 | return gi; |
| 346 | } |
| 347 | |
| 348 | /* Match a non-rooted pattern against basename and path suffixes. */ |
| 349 | static bool match_unrooted(const char *pattern, const char *rel_path, const char *basename) { |
no test coverage detected