| 284 | } |
| 285 | |
| 286 | cbm_gitignore_t *cbm_gitignore_load(const char *path) { |
| 287 | if (!path) { |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | FILE *f = cbm_fopen(path, "r"); |
| 292 | if (!f) { |
| 293 | return NULL; |
| 294 | } |
| 295 | |
| 296 | /* Read entire file */ |
| 297 | (void)fseek(f, 0, SEEK_END); |
| 298 | long size = ftell(f); |
| 299 | (void)fseek(f, 0, SEEK_SET); |
| 300 | |
| 301 | if (size <= 0) { |
| 302 | (void)fclose(f); |
| 303 | return cbm_gitignore_parse(""); |
| 304 | } |
| 305 | |
| 306 | char *buf = malloc(size + SKIP_ONE); |
| 307 | if (!buf) { |
| 308 | (void)fclose(f); |
| 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | size_t n = fread(buf, SKIP_ONE, size, f); |
| 313 | buf[n] = '\0'; |
| 314 | (void)fclose(f); |
| 315 | |
| 316 | cbm_gitignore_t *gi = cbm_gitignore_parse(buf); |
| 317 | free(buf); |
| 318 | return gi; |
| 319 | } |
| 320 | |
| 321 | /* Match a non-rooted pattern against basename and path suffixes. */ |
| 322 | static bool match_unrooted(const char *pattern, const char *rel_path, const char *basename) { |
no test coverage detected